Altering "varargs" (add|remove|retain)All methods in Jaggregate
Jaggregate, my Java-5-only Smalltalk-ish collections library, has collections that support the Java collections' notions of addAll()
, removeAll()
, and retainAll()
. For usability's sake, there are three overloads of each:
void addAll( jaggregate.Collection<? extends E> others ); void addAll( E... others ); void addAll( java.lang.Iterable<? extends E> others ); boolean removeAll( jaggregate.Collection<? extends E> others ); boolean removeAll( E... others ); boolean removeAll( java.lang.Iterable<? extends E> others ); boolean retainAll( jaggregate.Collection<? extends E> others ); boolean retainAll( E... others ); boolean retainAll( java.lang.Iterable<? extends E> others );
The "varargs" forms allow specification of a real array argument, or of a variable-length argument list:
OrderedCollection<Integer> primes = new OrderedCollection<Integer>(); primes.addAll( new Integer[] { 2, 3, 5, 7 } ); primes.addAll( 11, 13, 17, 19 );
I made a mistake in the specification of the "varargs" overloads. As written, they allow a zero-length argument list. At best, addAll()
just looks goofy:
primes.addAll(); // add all what? to where?
And removeAll()
and retainAll()
get downright confusing:
primes.removeAll(); // removes nothing primes.retainAll(); // removes everything
So, I decided to change the "varargs" overloads to:
void addAll( E newElement, E... moreNewElements ); boolean removeAll( E oldElement, E... moreOldElements ); boolean retainAll( E keeper, E... moreKeepers );
Now, zero-arg calls to the *All()
methods won't compile (hopefully there weren't any out there to begin with), and if you really mean to hand the methods zero args, you can still do so with an array type rather than a varargs list.