Interface Set<T>

Type Parameters:
T - The type of item to be stored in the set.
All Superinterfaces:
java.lang.Iterable<T>

public interface Set<T>
extends java.lang.Iterable<T>

An ADT that represents a set: a bunch of items that must be distinct from each other, stored with no defined order.


Method Summary
 void add(T item)
          Adds the given item to the set, ignoring duplicates.
 void clear()
          Removes all items from the set.
 boolean contains(T item)
          Checks whether the given item is in the set.
 Set<T> intersect(Set<T> otherSet)
          Creates a new Set and returns an intersections of this set and otherSet.
 boolean isEmpty()
          Returns whether the set is empty.
 java.util.Iterator<T> iterator()
          Returns an iterator over the items in the set (which will access the items in some arbitrary order).
 boolean remove(T item)
          Removes the given item.
 int size()
          Returns the number of items in the set.
 java.lang.Object[] toArray()
          Returns an array containing the same contents as this set, in an arbitrary order.
 Set<T> union(Set<T> otherSet)
          Creates a new Set and returns a union of this set and otherSet.
 

Method Detail

add

void add(T item)
Adds the given item to the set, ignoring duplicates.


remove

boolean remove(T item)
Removes the given item.

Returns:
False if the item wasn't in the set before.

contains

boolean contains(T item)
Checks whether the given item is in the set.


size

int size()
Returns the number of items in the set.

Returns:
the number of items in the set

isEmpty

boolean isEmpty()
Returns whether the set is empty.


clear

void clear()
Removes all items from the set.


union

Set<T> union(Set<T> otherSet)
Creates a new Set and returns a union of this set and otherSet.

Parameters:
otherSet - A set to combine with this set.
Returns:
The union of the two sets.

intersect

Set<T> intersect(Set<T> otherSet)
Creates a new Set and returns an intersections of this set and otherSet.

Parameters:
otherSet - A set to combine with this set.
Returns:
The intersection of the two sets.

iterator

java.util.Iterator<T> iterator()
Returns an iterator over the items in the set (which will access the items in some arbitrary order).

Specified by:
iterator in interface java.lang.Iterable<T>

toArray

java.lang.Object[] toArray()
Returns an array containing the same contents as this set, in an arbitrary order. Note that, for technical reasons, the type of the items contained in the set can't be communicated properly to the caller, so an array of Objects gets returned.

Returns:
an array of length size(), with the same items in it as are stored in the set.