sdsu.util
Class SortedList

java.lang.Object
  |
  +--sdsu.util.List
        |
        +--sdsu.util.SortedList

public class SortedList
extends List
implements SortedCollection

A SortedList is a list of objects kept in sorted order. A Comparer object is needed to compare objects in the list, as there is no standard compare operation for objects. Comparer class for standard types are found in the package sdsu.compare. For object types not covered, make a sublclass of sdsu.compare.Comparer;

Version:
2.0 10 January 1998
Author:
Roger Whitney (whitney@cs.sdsu.edu), Mark Boyns
See Also:
List, Comparer, SortedCollection, Serialized Form

Constructor Summary
SortedList(Comparer listOrder)
          Create a new SortedList using the Comparer object listOrder to define the order on elements.
SortedList(Comparer listOrder, int initialSize)
          Create a new SortedList using the Comparer object listOrder to define the order on elements.
 
Method Summary
 void addElement(java.lang.Object elementToAdd)
          Adds the specified object in proper location to keep list sorted.
 void addElements(java.lang.Object[] elementsToAdd)
          Adds the elements of an array to a SortedList.
 void addElements(SortedCollection elementsToAdd)
          Adds the elements of a SortedCollection to a SortedList.
 void addElements(java.util.Vector elementsToAdd)
          Adds the elements of a Vector to a SortedList.
 java.lang.Object clone()
          Clones this list.
static SortedList doubleSorter()
          Returns a sortedList object that will sort floats and doubles.
 Comparer getComparer()
          Returns the comparer object used to order list.
 int indexOf(java.lang.Object elem, int index)
          Searches for the specified object, starting at the specified position and returns an index to it.
 void insertElementAt(java.lang.Object object, int index)
          Inserts the specified object in the proper location in the sorted list.
static SortedList integerSorter()
          Returns a sortedList object that will sort integers.
 void resort(Comparer newOrder)
          Resorts the list using the new comparer to define the ordering of the elements.
 OrderedCollection reversed()
          Returns a SortedList with elements in the reverse order from present SortedList
 void setElementAt(java.lang.Object object, int index)
          Sets the element at the specified index to be the specified object and resorts the list.
static SortedList stringSorter()
          Returns a sortedList object that will sort strings.
 
Methods inherited from class sdsu.util.List
addElement, addElement, capacity, contains, doubleAt, elementAt, elements, elementsReversed, ensureCapacity, firstElement, fromString, getMetaData, indexOf, intAt, isEmpty, lastElement, lastIndexOf, lastIndexOf, load, load, removeAllElements, removeElement, removeElementAt, replaceElements, save, setMetaData, setSeparatorChar, setSize, setTokenCharacters, shuffled, size, toArray, toString, toString, toVector, trimToSize
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SortedList

public SortedList(Comparer listOrder)
Create a new SortedList using the Comparer object listOrder to define the order on elements.

SortedList

public SortedList(Comparer listOrder,
                  int initialSize)
Create a new SortedList using the Comparer object listOrder to define the order on elements. The sortedlist will have room for initialSize elements before it needs to grow.
Method Detail

integerSorter

public static SortedList integerSorter()
Returns a sortedList object that will sort integers.

doubleSorter

public static SortedList doubleSorter()
Returns a sortedList object that will sort floats and doubles.

stringSorter

public static SortedList stringSorter()
Returns a sortedList object that will sort strings.

getComparer

public Comparer getComparer()
Returns the comparer object used to order list.
Specified by:
getComparer in interface SortedCollection

addElement

public void addElement(java.lang.Object elementToAdd)
Adds the specified object in proper location to keep list sorted.
Parameters:
elementToAdd - the element to be added
Overrides:
addElement in class List

addElements

public void addElements(SortedCollection elementsToAdd)
Adds the elements of a SortedCollection to a SortedList. Resulting list is sorted
Specified by:
addElements in interface SortedCollection
Parameters:
elementsToAdd - the elements to be added

addElements

public void addElements(java.util.Vector elementsToAdd)
Adds the elements of a Vector to a SortedList. Resulting list is sorted
Parameters:
elementsToAdd - the elements to be added
Overrides:
addElements in class List

addElements

public void addElements(java.lang.Object[] elementsToAdd)
Adds the elements of an array to a SortedList. Resulting list is sorted
Parameters:
elementsToAdd - the elements to be added
Overrides:
addElements in class List

indexOf

public final int indexOf(java.lang.Object elem,
                         int index)
Searches for the specified object, starting at the specified position and returns an index to it.
Parameters:
elem - the desired element
index - the index where to start searching
Returns:
the index of the element, or -1 if it was not found.
Overrides:
indexOf in class List

insertElementAt

public void insertElementAt(java.lang.Object object,
                            int index)
Inserts the specified object in the proper location in the sorted list. Should not this method on sorted list. Use addElement.
Parameters:
object - the element to insert
index - not used
Overrides:
insertElementAt in class List

setElementAt

public void setElementAt(java.lang.Object object,
                         int index)
Sets the element at the specified index to be the specified object and resorts the list. The previous element at that position is discarded.
Parameters:
object - what the element is to be set to
index - the specified index
Throws:
java.lang.ArrayIndexOutOfBoundsException - If the index was invalid.
Overrides:
setElementAt in class List

reversed

public OrderedCollection reversed()
Returns a SortedList with elements in the reverse order from present SortedList
Overrides:
reversed in class List

resort

public void resort(Comparer newOrder)
Resorts the list using the new comparer to define the ordering of the elements.
Specified by:
resort in interface SortedCollection

clone

public java.lang.Object clone()
Clones this list. The elements are not cloned.
Overrides:
clone in class List