jds.collection
Class SetAdapter

java.lang.Object
  |
  +--jds.collection.SetAdapter

public class SetAdapter
extends java.lang.Object
implements Set

SetAdapter set formed as a wrapper around existing collection; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Enumeration, Serializable, Serialized Form

Constructor Summary
SetAdapter(Bag s)
          initialize set adapter by wrapping around an existing set
 
Method Summary
 void addElement(java.lang.Object val)
          add a new value to the collection
 boolean containsElement(java.lang.Object val)
          see if collection contains value
 void differenceWith(Bag aSet)
          form difference from argument set
 java.util.Enumeration elements()
          Yields enumerator for collection
 java.lang.Object findElement(java.lang.Object val)
          find element that will test equal to value
 void intersectWith(Bag aSet)
          form intersection with argument set
 boolean isEmpty()
          Determines whether the collection is empty
 void removeElement(java.lang.Object val)
          remove a new value from the collection
 int size()
          Determines number of elements in collection
 boolean subsetOf(Bag aSet)
          see if current set is subset of argument set
 void unionWith(Bag aSet)
          form union with argument set
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SetAdapter

public SetAdapter(Bag s)
initialize set adapter by wrapping around an existing set
Parameters:
s - existing set to hold underlying data values
Method Detail

isEmpty

public boolean isEmpty()
Determines whether the collection is empty
Returns:
true if the collection is empty

size

public int size()
Determines number of elements in collection
Returns:
number of elements in collection as integer

elements

public java.util.Enumeration elements()
Yields enumerator for collection
Returns:
an Enumeration that will yield the elements of the collection
See Also:
Enumeration

addElement

public void addElement(java.lang.Object val)
add a new value to the collection
Parameters:
value - element to be inserted into collection

containsElement

public boolean containsElement(java.lang.Object val)
see if collection contains value
Parameters:
value - element to be tested
Returns:
true if collection contains value

findElement

public java.lang.Object findElement(java.lang.Object val)
find element that will test equal to value
Parameters:
value - element to be tested
Returns:
first value that is equals to argument
Throws:
java.util.NoSuchElementException - no matching value

removeElement

public void removeElement(java.lang.Object val)
remove a new value from the collection
Parameters:
value - element to be removed from collection
Throws:
java.util.NoSuchElementException - no matching value

unionWith

public void unionWith(Bag aSet)
form union with argument set
Specified by:
unionWith in interface Set
Parameters:
aSet - collection to be joined to current

intersectWith

public void intersectWith(Bag aSet)
form intersection with argument set
Specified by:
intersectWith in interface Set
Parameters:
aSet - collection to be intersected with current

differenceWith

public void differenceWith(Bag aSet)
form difference from argument set
Specified by:
differenceWith in interface Set
Parameters:
aSet - collection to be compared to current

subsetOf

public boolean subsetOf(Bag aSet)
see if current set is subset of argument set
Specified by:
subsetOf in interface Set
Parameters:
aSet - collection to be tested against
Returns:
true if current collection is subset of argument collection