structure
Class SetVector

java.lang.Object
  extended by structure.AbstractStructure
      extended by structure.AbstractSet
          extended by structure.SetVector
All Implemented Interfaces:
Set, Structure

public class SetVector
extends AbstractSet

An implementation of a set using vectors


Field Summary
protected  Vector data
          The underlying structure --- a vector.
 
Constructor Summary
SetVector()
          Construct a new set.
SetVector(Structure other)
          Construct a new set from another structure.
 
Method Summary
 void add(java.lang.Object e)
          Add an element to set, if not already present.
 void addAll(Structure other)
          Compute the union of this set with other.
 void clear()
          Remove all the elements from the set.
 java.lang.Object clone()
          Returns a shallow clone of this set.
 boolean contains(java.lang.Object e)
          Returns true if value is an element of the set.
 boolean containsAll(Structure other)
          Determine if this set is a subset of other.
 boolean isEmpty()
          Determine if the set is empty.
 java.util.Iterator iterator()
          Construct an traversal to traverse the elements of the set.
 java.lang.Object remove(java.lang.Object e)
          Remove an element from the set.
 void removeAll(Structure other)
          Compute the difference between two sets.
 void retainAll(Structure other)
          Compute the intersection of this set and other.
 int size()
          Determine the number of elements in the set.
 java.lang.String toString()
          Construct a string representation of the set.
 
Methods inherited from class structure.AbstractStructure
elements, hashCode, values
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface structure.Structure
elements, values
 

Field Detail

data

protected Vector data
The underlying structure --- a vector.

Constructor Detail

SetVector

public SetVector()
Construct a new set.

Postcondition:
constructs a new, empty set

SetVector

public SetVector(Structure other)
Construct a new set from another structure.

Postcondition:
constructs a new set with elements from other
Method Detail

clear

public void clear()
Remove all the elements from the set.

Postcondition:
elements of set are removed

isEmpty

public boolean isEmpty()
Determine if the set is empty.

Specified by:
isEmpty in interface Structure
Overrides:
isEmpty in class AbstractStructure
Returns:
True iff there are no elements in set.
Postcondition:
returns true iff set is empty

add

public void add(java.lang.Object e)
Add an element to set, if not already present.

Parameters:
e - The new value to be added to set.
Precondition:
e is non-null object
Postcondition:
adds element e to set

remove

public java.lang.Object remove(java.lang.Object e)
Remove an element from the set.

Parameters:
e - The element of the set to be removed.
Returns:
The value actually removed.
Precondition:
e is non-null object
Postcondition:
e is removed from set, value returned

contains

public boolean contains(java.lang.Object e)
Returns true if value is an element of the set.

Specified by:
contains in interface Structure
Overrides:
contains in class AbstractStructure
Parameters:
e - The element sought in set.
Returns:
True iff the element is in the set.
Precondition:
e is non-null
Postcondition:
returns true iff e is in set

containsAll

public boolean containsAll(Structure other)
Determine if this set is a subset of other.

Specified by:
containsAll in interface Set
Overrides:
containsAll in class AbstractSet
Parameters:
other - The potential superset.
Precondition:
other is non-null reference to set
Postcondition:
returns true iff this set is subset of other

clone

public java.lang.Object clone()
Returns a shallow clone of this set.

Overrides:
clone in class java.lang.Object
Returns:
A new set with same values.
Postcondition:
returns a copy of set

addAll

public void addAll(Structure other)
Compute the union of this set with other.

Specified by:
addAll in interface Set
Overrides:
addAll in class AbstractSet
Parameters:
other - The set to be unioned with this.
Precondition:
other is a non-null structure
Postcondition:
add all elements of other to set, if needed

retainAll

public void retainAll(Structure other)
Compute the intersection of this set and other. Members of result are in both this and other.

Specified by:
retainAll in interface Set
Overrides:
retainAll in class AbstractSet
Parameters:
other - The other set to be intersected with this.
Precondition:
other is non-null reference to set
Postcondition:
returns set containing intersection of this and other

removeAll

public void removeAll(Structure other)
Compute the difference between two sets. Values of the result are members of this, but not other.

Specified by:
removeAll in interface Set
Overrides:
removeAll in class AbstractSet
Parameters:
other - The set whose values are to be eliminated from this.
Precondition:
other is non-null reference to set
Postcondition:
returns set containing difference of this and other

iterator

public java.util.Iterator iterator()
Construct an traversal to traverse the elements of the set. Elements will not appear in any particular order.

Returns:
An traversal for inspecting members of the set.
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()
Postcondition:
returns traversal to traverse the elements of set

size

public int size()
Determine the number of elements in the set.

Returns:
The number of elements in the set.
Postcondition:
returns number of elements in set

toString

public java.lang.String toString()
Construct a string representation of the set.

Overrides:
toString in class java.lang.Object
Returns:
A string representing the set.
Postcondition:
returns a string representation of set