Class Set

java.lang.Object
  |
  +--Set

public class Set
extends java.lang.Object
implements java.lang.Cloneable

Implements a Set using a cs111.LinkedList. A Set is an unordered collection of unique objects.


Constructor Summary
Set()
          Create a new Set, initially empty.
Set(Set s)
          Create a new Set with the same elements as in the given set.
 
Method Summary
 void addTo(java.lang.Object o)
          Add an object to the Set.
protected  java.lang.Object clone()
          We will make a clone of a Set.
protected  LinkedList getList()
          Return the LinkedList which holds this Set
 boolean isEmpty()
          See if the Set is empty.
 boolean memberOf(java.lang.Object o)
          See if an Object is a member of a Set
 java.lang.String toString()
          Return a String representation of a Set.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Set

public Set()
Create a new Set, initially empty.

Set

public Set(Set s)
Create a new Set with the same elements as in the given set.
Parameters:
s - the Set to take the elements from
Method Detail

isEmpty

public boolean isEmpty()
See if the Set is empty.
Returns:
true if the list is empty, false otherwise

addTo

public void addTo(java.lang.Object o)
Add an object to the Set. This will print a warning if the element is already in the Set.
Parameters:
o - The Object to be added.

memberOf

public boolean memberOf(java.lang.Object o)
See if an Object is a member of a Set
Parameters:
o - is object whose membership is tested
Returns:
true if the Object is a member of the Set, false otherwise

toString

public java.lang.String toString()
Return a String representation of a Set. This assumes every element in the Set implements the toString() method.
Overrides:
toString in class java.lang.Object
Returns:
The Set as a String

getList

protected LinkedList getList()
Return the LinkedList which holds this Set
Returns:
the LinkedList which represents this Set.

clone

protected java.lang.Object clone()
We will make a clone of a Set. The clone of the Set will hold "pointers" to the same objects that are in the original set. Altering an Object in one Set will alter the Object in the other Set.
Overrides:
clone in class java.lang.Object