Migrating methods in Collections

Doug Lea dl at cs.oswego.edu
Thu Dec 24 13:24:44 UTC 2015


You might look at discussions so far as conceptually adding a
super-interface to Collection, but jamming all the methods
into Collection itself. It might be easier to pretend otherwise
for a while. If we had some really good names for these, we might
even prefer this way.

Here's sketch of Collection (Not yet for List and Map)

interface AnyCollection<E> {
     boolean isEmpty();
     boolean contains(E e); // not Object

     boolean add(E e);
     boolean remove(E e);   // not Object
     boolean removeIf(Predicate<? super E> filter);
     void clear();

     Iterator<E> iterator();
     Stream<E> stream();
     Stream<E> parallelStream();

     boolean addAll(AnyCollection<? extends E> c);
     boolean containsAll(AnyCollection<? extends E> c); // not Collection<?>
     boolean removeAll(AnyCollection<? extends E> c);   // not Collection<?>
     boolean retainAll(AnyCollection<? extends E> c);   // not Collection<?>

     // to address other issues:
     long elementCount();   // not size()
     AnyCollection<E> adding(E e);
     AnyCollection<E> removing(E e);
}

interface Collection<E> extends AnyCollection<E> {
     int size();
     boolean contains(Object o); // contravariant arg
     boolean remove(Object o);   // contravariant arg

     Object[] toArray();
     <T> T[] toArray(T[] a);

     boolean equals(Object o);   // declare for sake of Collection spec
     int hashCode();             // declare for sake of Collection spec

     boolean containsAll(Collection<?> c);
     boolean removeAll(Collection<?> c);
     boolean retainAll(Collection<?> c);
}



More information about the valhalla-spec-experts mailing list