|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectstructure.AbstractStructure<ELTTYPE>
structure.OrderedList<ELTTYPE>
public class OrderedList<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
A class that implements a collection of values that are kept in order. Base values must be comparable. Unlike Lists there is no notion of head or tail.
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, as follows:
public static void main(String[] argv){
//instantiate an ordered vector
OrderedList> v = new #OrderedList>() ;
//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");
}
}
Vector| Constructor Summary | |
|---|---|
OrderedList()
Construct an empty ordered list |
|
OrderedList(java.util.Comparator<? super ELTTYPE> ordering)
Construct an empty ordered list with alternative ordering |
|
| Method Summary | |
|---|---|
void |
add(ELTTYPE value)
Add a value to the ordered list, keeping values in order |
void |
clear()
Remove all the elements from the ordered list |
boolean |
contains(ELTTYPE value)
Determine if the ordered list contains a value |
boolean |
isEmpty()
Determine if the list is empty |
java.util.Iterator<ELTTYPE> |
iterator()
Construct an iterator for traversing elements of ordered list in ascending order |
ELTTYPE |
remove(ELTTYPE value)
Remove a value from the ordered list. |
int |
size()
Determine the number of elements in the list |
java.lang.String |
toString()
Generate string representation of the ordered list |
| 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 OrderedList()
public OrderedList(java.util.Comparator<? super ELTTYPE> ordering)
ordering - the Comparator to be used in comparison| Method Detail |
|---|
public void clear()
clear in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>public void add(ELTTYPE value)
add in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>value - The value to be added to the listpublic boolean contains(ELTTYPE value)
contains in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>contains in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>value - The value sought in the list
public ELTTYPE remove(ELTTYPE value)
remove in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>value - The value to be removed
public int size()
size in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>public boolean isEmpty()
isEmpty in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>isEmpty in class AbstractStructure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>public java.util.Iterator<ELTTYPE> iterator()
iterator in interface java.lang.Iterable<ELTTYPE extends java.lang.Comparable<ELTTYPE>>iterator in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>AbstractIterator,
Iterator,
Enumeration,
Structure.elements()public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||