mckay.utilities.vectorsorter
Class StringSortableVector

java.lang.Object
  extended by mckay.utilities.vectorsorter.StringSortableVector

public class StringSortableVector
extends java.lang.Object

A simplistic example of how the SortableVector class might be used in practice. This implementation assumes that the vector is storing and sorting strings. An internal class is included that implements QuicksortComparator.

This class might be used as follows, for example:

StringSortableVector sv = new StringSortableVector();
sv.addElement("d");
sv.addElement("A");
sv.addElement("C");
sv.addElement("c");
sv.addElement("b");
sv.addElement("B");
sv.addElement("D");
sv.addElement("a");
Enumeration e = sv.elements();
while(e.hasMoreElements()) System.out.println(e.nextElement());

This approach to the QuickSort algorithm is derived from Bruce Eckel's implementation, which can be found at: http://www.codeguru.com/java/tij/tij0091.shtml


Constructor Summary
StringSortableVector()
          Initializes the object.
 
Method Summary
 void addElement(java.lang.String s)
          Adds the given string to the SortableVector stored in this object.
 java.lang.String elementAt(int index)
          Returns the string stored at the given index of the SortableVector stored in this object.
 java.util.Enumeration elements()
          Returns an Enumeration of all elements stored in the SortableVector stored in this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringSortableVector

public StringSortableVector()
Initializes the object.

Method Detail

addElement

public void addElement(java.lang.String s)
Adds the given string to the SortableVector stored in this object.

Parameters:
s - The string to add.

elementAt

public java.lang.String elementAt(int index)
Returns the string stored at the given index of the SortableVector stored in this object. If the object has not already been sorted, then it is sorted first.

Parameters:
index - The post-sorting index of the object to return.
Returns:
The string stored at the given index.

elements

public java.util.Enumeration elements()
Returns an Enumeration of all elements stored in the SortableVector stored in this object. Sorting is performed if it has not already been performed.

Returns:
The post-sorted stored strings.