jds.collection
Class SortedList

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

public class SortedList
extends java.lang.Object
implements Sorted, Set, FindMin

SortedList - a linked list that is maintained in order; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Collection, Serialized Form

Constructor Summary
SortedList(java.util.Comparator c)
          initialize a sorted list
 
Method Summary
 void addElement(java.lang.Object newElement)
          add a new value to the collection
 boolean containsElement(java.lang.Object val)
          see if collection contains value
 void differenceWith(Bag newSet)
          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
 java.lang.Object getFirst()
          yields the smallest element in collection
 void intersectWith(Bag newSet)
          form intersection with argument set
 boolean isEmpty()
          Determines whether the collection is empty
 void mergeWith(Collection newSet)
           
 void removeElement(java.lang.Object val)
          remove a new value from the collection
 void removeFirst()
          removes the smallest element in collection
 int size()
          Determines number of elements in collection
 boolean subsetOf(Bag newSet)
          see if current set is subset of argument set
 void unionWith(Bag newSet)
          form union with argument set
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedList

public SortedList(java.util.Comparator c)
initialize a sorted list
Parameters:
c - the comparator object
Method Detail

elements

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

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

addElement

public void addElement(java.lang.Object newElement)
add a new value to the collection
Specified by:
addElement in interface FindMin
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

getFirst

public java.lang.Object getFirst()
yields the smallest element in collection
Specified by:
getFirst in interface FindMin
Returns:
the first (smallest) value in collection

removeFirst

public void removeFirst()
removes the smallest element in collection
Specified by:
removeFirst in interface FindMin

mergeWith

public void mergeWith(Collection newSet)

unionWith

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

intersectWith

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

differenceWith

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

subsetOf

public boolean subsetOf(Bag newSet)
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