From af5ebf8cc73a2467d5ad151451871fc0199aa88a Mon Sep 17 00:00:00 2001 From: samskivert Date: Tue, 14 Jul 2009 17:53:00 +0000 Subject: [PATCH] Fixed ArrayIntSet constructor, made equals() use AbstractSet when not comparing against another ArrayIntSet which will provide contents-based equality with other sets. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2593 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- src/java/com/samskivert/util/ArrayIntSet.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/java/com/samskivert/util/ArrayIntSet.java b/src/java/com/samskivert/util/ArrayIntSet.java index f99e61a7..b50096fc 100644 --- a/src/java/com/samskivert/util/ArrayIntSet.java +++ b/src/java/com/samskivert/util/ArrayIntSet.java @@ -49,13 +49,11 @@ public class ArrayIntSet extends AbstractSet if (_size > 1) { int last = _values[0]; for (int ii = 1; ii < _size; ) { - if (values[ii] == last) { - // shift everything down 1 + if (_values[ii] == last) { // shift everything down 1 _size--; System.arraycopy(_values, ii + 1, _values, ii, _size - ii); - } else { - last = values[ii++]; + last = _values[ii++]; } } } @@ -383,21 +381,21 @@ public class ArrayIntSet extends AbstractSet @Override public boolean equals (Object o) { + // use an optimized equality test for another ArrayIntSet if (o instanceof ArrayIntSet) { ArrayIntSet other = (ArrayIntSet)o; - if (other._size == _size) { - for (int ii = 0; ii < _size; ii++) { - // we can't use Arrays.equals() because we only want to - // compare the first _size values - if (_values[ii] != other._values[ii]) { - return false; - } - } - return true; + if (other._size != _size) { + return false; } + // we can't use Arrays.equals() because we only want to compare the first _size values + for (int ii = 0; ii < _size; ii++) { + if (_values[ii] != other._values[ii]) { + return false; + } + } + return true; } - - return false; + return super.equals(o); } @Override