structure
Class OrderedVector<ELTTYPE extends java.lang.Comparable<ELTTYPE>>

java.lang.Object
  extended by structure.AbstractStructure<ELTTYPE>
      extended by structure.OrderedVector<ELTTYPE>
All Implemented Interfaces:
java.lang.Iterable<ELTTYPE>, OrderedStructure<ELTTYPE>, Structure<ELTTYPE>

public class OrderedVector<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
extends AbstractStructure<ELTTYPE>
implements OrderedStructure<ELTTYPE>

Implementation of an ordered structure implemented using a vector. Values are stored within this vector in increasing order. All values stored within an ordered vector must implement comparable.

Example Usage:

To determine the effect of the original Starwars™ movie on the careers of its stars, we could place ComparableAssociations between each star's name and the number of movies they have been in since Starwars™ into an ordered vector and print our the results.

 public static void main(String[] argv){
        //instantiate an ordered vector
        OrderedVector> v = new #OrderedVector>();
        
        //add the cast members of the original star wars along with
        //the number of films in which the have subsequently appeared
        v.add(new ComparableAssociation(new Integer(12),"Sir Alec Guiness"));
        v.add(new ComparableAssociation(new Integer(24),"Carrie Fisher"));
        v.add(new ComparableAssociation(new Integer(28),"Harrison Ford")); 
        v.add(new ComparableAssociation(new Integer(28),"Mark Hamill"));

        //print out the results
        for(Iterator> i = v.iterator(); i.hasNext();){
            ComparableAssociation> actor = i.next();
            System.out.println(actor.getValue() + " has been in " + 
                               actor.getKey() + " movies since Star Wars"); 
        }
   }
 

See Also:
Vector

Constructor Summary
OrderedVector()
          Construct an empty ordered vector
 
Method Summary
 void add(ELTTYPE value)
          Add a comparable value to an ordered vector
 void clear()
          Removes all the values from a an ordered vector
 boolean contains(ELTTYPE value)
          Determine if a comparable value is a member of the ordered vector
 boolean isEmpty()
          Determine if the ordered vector is empty.
 java.util.Iterator<ELTTYPE> iterator()
          Construct an iterator to traverse the ordered vector in ascending order
 ELTTYPE remove(ELTTYPE value)
          Remove a comparable value from an ordered vector At most one value is removed
 int size()
          Determine the number of elements within the ordered vector
 java.lang.String toString()
          Construct a string representation of an ordered vector
 
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

OrderedVector

public OrderedVector()
Construct an empty ordered vector

Post:
constructs an empty, ordered vector
Method Detail

add

public void add(ELTTYPE value)
Add a comparable value to an ordered vector

Specified by:
add in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Parameters:
value - The comparable value to be added to the ordered vector
Pre:
value is non-null
Post:
inserts value, leaves vector in order

contains

public boolean contains(ELTTYPE value)
Determine if a comparable value is a member of the ordered vector

Specified by:
contains in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Overrides:
contains in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Parameters:
value - The comparable value sought
Returns:
True if the value is found within the ordered vector
Pre:
value is non-null
Post:
returns true if the value is in the vector

remove

public ELTTYPE remove(ELTTYPE value)
Remove a comparable value from an ordered vector At most one value is removed

Specified by:
remove in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Parameters:
value - The comparable value to be removed
Returns:
The actual comparable removed
Pre:
value is non-null
Post:
removes one instance of value, if found in vector

isEmpty

public boolean isEmpty()
Determine if the ordered vector is empty.

Specified by:
isEmpty in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Overrides:
isEmpty in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Returns:
True iff the ordered vector is empty
Post:
returns true if the OrderedVector is empty

clear

public void clear()
Removes all the values from a an ordered vector

Specified by:
clear in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Post:
vector is emptied

size

public int size()
Determine the number of elements within the ordered vector

Specified by:
size in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Returns:
The number of elements within the ordered vector
Post:
returns the number of elements in vector

iterator

public java.util.Iterator<ELTTYPE> iterator()
Construct an iterator to traverse the ordered vector in ascending order

Specified by:
iterator in interface java.lang.Iterable<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Specified by:
iterator in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
Returns:
An iterator to traverse the ordered vector
See Also:
AbstractIterator, Iterator, Enumeration, Structure.elements()
Post:
returns an iterator for traversing vector

toString

public java.lang.String toString()
Construct a string representation of an ordered vector

Overrides:
toString in class java.lang.Object
Returns:
The string representing the ordered vector
Pre:
returns string representation of ordered vector