|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--structure.AbstractStructure | +--structure.OrderedVector
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 = newOrderedVector()
; //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 = (ComparableAssociation)i.next(); System.out.println(actor.getValue() + " has been in " + actor.getKey() + " movies since Star Wars"); } }
Vector
Field Summary | |
protected Vector |
data
The vector of values. |
Constructor Summary | |
OrderedVector()
Construct an empty ordered vector |
Method Summary | |
void |
add(Object value)
Add a comparable value to an ordered vector |
void |
clear()
Removes all the values from a an ordered vector |
boolean |
contains(Object value)
Determine if a comparable value is a member of the ordered vector |
protected int |
indexOf(Comparable target)
|
boolean |
isEmpty()
Determine if the ordered vector is empty. |
Iterator |
iterator()
Construct an iterator to traverse the ordered vector in ascending order |
Object |
remove(Object 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 |
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 |
|
Methods inherited from interface structure.Structure |
elements, values |
Field Detail |
protected Vector data
Constructor Detail |
public OrderedVector()
Method Detail |
public void add(Object value)
add
in interface Structure
value
- The comparable value to be added to the ordered vectorpublic boolean contains(Object value)
contains
in interface Structure
contains
in class AbstractStructure
value
- The comparable value soughtpublic Object remove(Object value)
remove
in interface Structure
value
- The comparable value to be removedpublic boolean isEmpty()
isEmpty
in interface Structure
isEmpty
in class AbstractStructure
public void clear()
clear
in interface Structure
public int size()
size
in interface Structure
public Iterator iterator()
iterator
in interface Structure
protected int indexOf(Comparable target)
public String toString()
toString
in class Object
|
© 1998-2002 McGraw-Hill | |||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |