uk.co.ist.mwt
Class Sorter

java.lang.Object
  |
  +--uk.co.ist.mwt.Sorter

public class Sorter
extends java.lang.Object
implements java.util.Enumeration

A Sorter knows how to sort an array of objects which implement the Comparable interface; it should be constructed with the list, and then the elements should be read out using the normal Enumeration interface.


Field Summary
protected  int nextElt
          The index of the next element to return when enumerating
protected  Comparable[] sorted
          The array of things to sort
 
Constructor Summary
Sorter(Comparable[] objects)
          Initialises the class; copies the array into a private sorted version of itself.
 
Method Summary
protected  void doInit(Comparable[] objects)
          The real constructor, in a separate method so that the constructor can be overridden with something which wraps up the input objects with some Comparable type or similar.
 boolean hasMoreElements()
          When enumerating the results of a sort, tells you if there are any more elements to be enumerated
 java.lang.Object nextElement()
          When enumerating the results of a sort, returns the next element
 int numElements()
          Returns the number of elements in the array we're dealing with
 void resetEnum()
          When enumerating, reset so that the enumeration can begin from the start
protected  void sortMyArray()
          Sorts the array contained in this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sorted

protected Comparable[] sorted
The array of things to sort

nextElt

protected int nextElt
The index of the next element to return when enumerating
Constructor Detail

Sorter

public Sorter(Comparable[] objects)
Initialises the class; copies the array into a private sorted version of itself.
Method Detail

sortMyArray

protected void sortMyArray()
Sorts the array contained in this object. Override with your favourite algorithm

doInit

protected void doInit(Comparable[] objects)
The real constructor, in a separate method so that the constructor can be overridden with something which wraps up the input objects with some Comparable type or similar.

resetEnum

public void resetEnum()
When enumerating, reset so that the enumeration can begin from the start

numElements

public int numElements()
Returns the number of elements in the array we're dealing with

hasMoreElements

public boolean hasMoreElements()
When enumerating the results of a sort, tells you if there are any more elements to be enumerated
Specified by:
hasMoreElements in interface java.util.Enumeration

nextElement

public java.lang.Object nextElement()
When enumerating the results of a sort, returns the next element
Specified by:
nextElement in interface java.util.Enumeration