package sets; import java.util.Iterator; public interface Set<E> extends Iterable<E> { /* * Adds the specified element to this set if it is not * already present (optional operation). More formally, * adds the specified element e to this set if the set contains * no element e2 such that (e==null ? e2==null : e.equals(e2)). * If this set already contains the element, the call leaves * the set unchanged and returns false. * In combination with the restriction on constructors, * this ensures that sets never contain duplicate elements. */ boolean add(E e); /* * Removes all of the elements from this set (optional operation). * The set will be empty after this call returns. */ void clear(); /* * Returns true if this set contains the specified element. * More formally, returns true if and only if this set contains an element * e such that (o==null ? e==null : o.equals(e)). */ boolean contains(E e); /* * Compares the specified object with this set for equality. * Returns true if the specified object is also a set, the two sets * have the same size, and every member of the specified set is contained in this set * (or equivalently, every member of this set is contained in the specified set). * This definition ensures that the equals method works properly across different * implementations of the set interface. */ boolean equals(Object o); /* * Returns the union of this set and the other set. */ Set<E> union(Set<E> other); /* * Returns the intersection of this set and the other set. */ Set<E> intersection(Set<E> other); /* * Returns the difference of this set and the other set. */ Set<E> difference(Set<E> other); /* * Returns true if this set contains no elements. */ boolean isEmpty(); /* * Returns true if this set is a subset of the other set. */ boolean isSubsetOf(Set<E> other); /* * Returns an iterator over the elements in this set. * The elements are returned in no particular order * (unless this set is an instance of some class that provides a guarantee). */ Iterator<E> iterator(); /* * Removes the specified element from this set if it is present * (optional operation). More formally, removes an element e such * that (o==null ? e==null : o.equals(e)), if this set contains such an element. * Returns true if this set contained the element (or equivalently, * if this set changed as a result of the call). (This set will not contain the element * once the call returns.) */ boolean remove(E e); /* * Returns the number of elements in this set (its cardinality). * If this set contains more than Integer.MAX_VALUE elements, * returns Integer.MAX_VALUE */ int size(); /* * Returns the symmetric difference of this set and the other set. */ Set<E> symDifference(Set<E> other); /* * Returns an array containing all of the elements in this set. * If this set makes any guarantees as to what order its elements * are returned by its iterator, this method must return the elements * in the same order. */ Object[] toArray(); }