|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.AbstractStructure<ELTTYPE> structure.AbstractSet<ELTTYPE> structure.SetVector<ELTTYPE>
public class SetVector<ELTTYPE>
Implementation of a set of elements using a vector as the underlying storage mechanism. As with the mathematical object, the elements of the set are not duplicated. No order is implied or enforced in this structure, but simple set operations such as intersection, union, difference, and subset are provided.
Example Usage: Given a list of students who completed a computer science thesis in the 2001-2002 academic year at Williams College and a list of graduating computer science majors who are continuing on to graduate school, we could determine which thesis students are planning to attend graduate school as follows:
public static void main(String[] argv){ //thesis students in the class of '02 String[] thesis = new String[]{"Doug", "Evan", "Feng"}; //students continuing on to grad school String[] grad = new String[]{"Doug", "Feng", "Lida"}; //instantiate our sets Set thesisSet = newSetVector()
, gradSet = newSetVector()
; //build sets up for(int i = 0; i < thesis.length; i++) thesisSet.add(thesis[i])
; for(int i = 0; i < grad.length; i++) gradSet.add(grad[i])
; //calculate the intersection of the two sets thesisSet.retainAll(gradSet)
; System.out.println(thesisSet); }
Constructor Summary | |
---|---|
SetVector()
Construct a new set. |
|
SetVector(Structure<ELTTYPE> other)
Construct a new set from another structure. |
Method Summary | |
---|---|
void |
add(ELTTYPE e)
Add an element to set, if not already present. |
void |
addAll(Structure<ELTTYPE> 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(ELTTYPE e)
Returns true if value is an element of the set. |
boolean |
containsAll(Structure<ELTTYPE> other)
Determine if this set is a subset of other. |
boolean |
isEmpty()
Determine if the set is empty. |
java.util.Iterator<ELTTYPE> |
iterator()
Construct an traversal to traverse the elements of the set. |
static void |
main(java.lang.String[] argv)
|
ELTTYPE |
remove(ELTTYPE e)
Remove an element from the set. |
void |
removeAll(Structure<ELTTYPE> other)
Compute the difference between two sets. |
void |
retainAll(Structure<ELTTYPE> 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, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure.Structure |
---|
elements, values |
Constructor Detail |
---|
public SetVector()
public SetVector(Structure<ELTTYPE> other)
Method Detail |
---|
public void clear()
public boolean isEmpty()
isEmpty
in interface Structure<ELTTYPE>
isEmpty
in class AbstractStructure<ELTTYPE>
public void add(ELTTYPE e)
e
- The new value to be added to set.public ELTTYPE remove(ELTTYPE e)
e
- The element of the set to be removed.
public boolean contains(ELTTYPE e)
contains
in interface Structure<ELTTYPE>
contains
in class AbstractStructure<ELTTYPE>
e
- The element sought in set.
public boolean containsAll(Structure<ELTTYPE> other)
containsAll
in interface Set<ELTTYPE>
containsAll
in class AbstractSet<ELTTYPE>
other
- The potential superset.public java.lang.Object clone()
clone
in class java.lang.Object
public void addAll(Structure<ELTTYPE> other)
addAll
in interface Set<ELTTYPE>
addAll
in class AbstractSet<ELTTYPE>
other
- The set to be unioned with this.public void retainAll(Structure<ELTTYPE> other)
retainAll
in interface Set<ELTTYPE>
retainAll
in class AbstractSet<ELTTYPE>
other
- The other set to be intersected with this.public void removeAll(Structure<ELTTYPE> other)
removeAll
in interface Set<ELTTYPE>
removeAll
in class AbstractSet<ELTTYPE>
other
- The set whose values are to be eliminated from this.public java.util.Iterator<ELTTYPE> iterator()
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public int size()
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] argv)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |