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
This commit is contained in:
samskivert
2009-07-14 17:53:00 +00:00
parent b5af1884b3
commit af5ebf8cc7
+13 -15
View File
@@ -49,13 +49,11 @@ public class ArrayIntSet extends AbstractSet<Integer>
if (_size > 1) { if (_size > 1) {
int last = _values[0]; int last = _values[0];
for (int ii = 1; ii < _size; ) { for (int ii = 1; ii < _size; ) {
if (values[ii] == last) { if (_values[ii] == last) { // shift everything down 1
// shift everything down 1
_size--; _size--;
System.arraycopy(_values, ii + 1, _values, ii, _size - ii); System.arraycopy(_values, ii + 1, _values, ii, _size - ii);
} else { } else {
last = values[ii++]; last = _values[ii++];
} }
} }
} }
@@ -383,21 +381,21 @@ public class ArrayIntSet extends AbstractSet<Integer>
@Override @Override
public boolean equals (Object o) public boolean equals (Object o)
{ {
// use an optimized equality test for another ArrayIntSet
if (o instanceof ArrayIntSet) { if (o instanceof ArrayIntSet) {
ArrayIntSet other = (ArrayIntSet)o; ArrayIntSet other = (ArrayIntSet)o;
if (other._size == _size) { if (other._size != _size) {
for (int ii = 0; ii < _size; ii++) { return false;
// 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;
} }
// 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 super.equals(o);
return false;
} }
@Override @Override