AbstractCollection's isEmpty() calls size(). We can often do better:

- Provide an implementation in AbstractIntSet that checks the interator
  for at least one element.
- Override that in ArrayIntSet so that we're just checking our size again.
- Added optimized isEmpty()s for a few of the inner classes in IntSets.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2701 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
ray.j.greenwell
2010-01-14 21:25:52 +00:00
parent 8f24b4a8b8
commit e0e2f1cf7d
3 changed files with 22 additions and 2 deletions
@@ -71,6 +71,18 @@ public abstract class AbstractIntSet extends AbstractSet<Integer>
return size;
}
/**
* {@inheritDoc}
*
* <p>This implementation simply checks to see if the interator has a first element.
*/
@Override
public boolean isEmpty ()
{
// possibly dumb implementation. Override if you can do better.
return !interator().hasNext();
}
// from IntSet
public boolean add (int value)
{
@@ -268,12 +268,18 @@ public class ArrayIntSet extends AbstractIntSet
return values;
}
@Override // from AbstractSet<Integer>
@Override // from AbstractCollection<Integer>
public int size ()
{
return _size;
}
@Override // from AbstractCollection<Integer>
public boolean isEmpty ()
{
return (_size == 0);
}
@Override // from AbstractIntSet
public boolean retainAll (Collection<?> c)
{
+3 -1
View File
@@ -210,6 +210,7 @@ public class IntSets
{
@Override public boolean contains (int value) { return false; }
@Override public int size () { return 0; }
@Override public boolean isEmpty () { return true; }
public Interator interator ()
{
@@ -233,8 +234,9 @@ public class IntSets
_s = s;
}
@Override public int size () { return _s.size(); }
@Override public boolean contains (int value) { return _s.contains(value); }
@Override public int size () { return _s.size(); }
@Override public boolean isEmpty () { return _s.isEmpty(); }
public Interator interator ()
{