Interface ISet<E>

All Superinterfaces:
Iterable<E>
All Known Implementing Classes:
AbstractSet, SortedSet, UnsortedSet

public interface ISet<E>
extends Iterable<E>

An interface that models a set. Sets have no implied order and duplicate items are not allowed.


Method Summary
 boolean add(E item)
          Add an item to this set.
 boolean addAll(ISet<E> otherSet)
          A union operation.
 void clear()
          Make this set empty.
 boolean contains(E item)
          Determine if item is in this set.
 boolean containsAll(ISet<E> otherSet)
          Determine if all of the elements of otherSet are in this set.
 ISet<E> difference(ISet<E> otherSet)
          Create a new set that is the difference of this set and otherSet.
 boolean equals(Object other)
          Determine if tthis set is equal to other.
 ISet<E> intersection(ISet<E> otherSet)
          create a new set that is the intersection of this set and otherSet.
 Iterator<E> iterator()
          Return an Iterator object for the elements of this set.
 boolean remove(E item)
          Remove the specified item from this set if it is present.
 int size()
          Return the number of elements of this set.
 ISet<E> union(ISet<E> otherSet)
          Create a new set that is the union of this set and otherSet.
 

Method Detail

add

boolean add(E item)
Add an item to this set.

Parameters:
item - the item to be added to this set.
Returns:
true if this set changed as a result of this operation, false otherwise.

addAll

boolean addAll(ISet<E> otherSet)
A union operation. Add all items of otherSet that are not already present in this set to this set.

Parameters:
otherSet - != null
Returns:
true if this set changed as a result of this operation, false otherwise.

clear

void clear()
Make this set empty.
pre: none
post: size() = 0


contains

boolean contains(E item)
Determine if item is in this set.
pre: none

Parameters:
item - element whose presence is being tested
Returns:
true if this set contains the specified item, false otherwise.

containsAll

boolean containsAll(ISet<E> otherSet)
Determine if all of the elements of otherSet are in this set.

Parameters:
otherSet - != null
Returns:
true if this set contains all of the elements in otherSet, false otherwise.

difference

ISet<E> difference(ISet<E> otherSet)
Create a new set that is the difference of this set and otherSet. Return an ISet of elements that are in this Set but not in otherSet. Also called the relative complement.
Example: If ISet A contains [X, Y, Z] and ISet B contains [W, Z] then A.difference(B) would return an ISet with elements [X, Y] while B.difference(A) would return an ISet with elements [W].
pre: otherSet != null
post: returns a set that is the difference of this set and otherSet. Neither this set or otherSet are altered as a result of this operation.

Parameters:
otherSet - != null
Returns:
a set that is the difference of this set and otherSet

equals

boolean equals(Object other)
Determine if tthis set is equal to other. Two sets are equal if they have exactly the same elements.
pre: none

Overrides:
equals in class Object
Parameters:
other - the object to compare to this set
Returns:
true if other is a Set and has the same elements as this set

intersection

ISet<E> intersection(ISet<E> otherSet)
create a new set that is the intersection of this set and otherSet.
pre: otherSet != null

post: returns a set that is the intersection of this set and otherSet. Neither this set or otherSet are altered as a result of this operation.

Parameters:
otherSet - != null
Returns:
a set that is the intersection of this set and otherSet

iterator

Iterator<E> iterator()
Return an Iterator object for the elements of this set. pre: none

Specified by:
iterator in interface Iterable<E>
Returns:
an Iterator object for the elements of this set

remove

boolean remove(E item)
Remove the specified item from this set if it is present. pre: none

Parameters:
item - the item to remove from the set
Returns:
true if this set changed as a result of this operation, false otherwise

size

int size()
Return the number of elements of this set. pre: none

Returns:
the number of items in this set

union

ISet<E> union(ISet<E> otherSet)
Create a new set that is the union of this set and otherSet.
pre: otherSet != null
post: returns a set that is the union of this set and otherSet. Neither this set or otherSet are altered as a result of this operation.

Parameters:
otherSet - != null
Returns:
a set that is the union of this set and otherSet