com.uwyn.rife.tools
Class Sort

java.lang.Object
  extended by com.uwyn.rife.tools.Sort
Direct Known Subclasses:
SortListComparables

public abstract class Sort
extends Object

Generic class that implements the quicksort algorithm. Extending classes have to implement the abstract methods so that the sorting algorithm can perform the appropriate modifications to the extending class's datastructure.

Since:
1.0
Version:
$Revision: 3634 $
Author:
Geert Bevin (gbevin[remove] at uwyn dot com)

Constructor Summary
Sort()
           
 
Method Summary
protected abstract  int compare(Object element1, Object element2)
          Compares the entries, determining which one comes before the other.
protected abstract  Object elementAt(Object dataToSort, int position)
          Retrieves an entry from a certain position within the specified datastructure.
protected  void quickSort(Object dataToSort, int lo0, int hi0, boolean ascending)
          This method contains the actual sorting algorithm.
 void sort(Object dataToSort, int lastElementPosition, boolean ascending)
          Starts the sorting of the provided datastructure.
protected abstract  void swap(Object dataToSort, int position1, int position2)
          Swaps the position of two entries in the provided datastructure.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sort

public Sort()
Method Detail

sort

public final void sort(Object dataToSort,
                       int lastElementPosition,
                       boolean ascending)
Starts the sorting of the provided datastructure.

Parameters:
dataToSort - An Object instance that points to the datastructure that has to be sorted. The extending class should know how to manipulate this particular datastructure.
lastElementPosition - An integer that specifies the position of the last element in the provided datastructure.
ascending - true of the data has to be sorted in an ascending fashion and false otherwise
Since:
1.0

quickSort

protected final void quickSort(Object dataToSort,
                               int lo0,
                               int hi0,
                               boolean ascending)
This method contains the actual sorting algorithm.

Parameters:
dataToSort - An Object instance that points to the datastructure that has to be sorted.
lo0 - An integer indicating the bottom boundary of the range that will be sorted.
hi0 - An integer indicating the upper boundary of the range that will be sorted.
ascending - true of the data has to be sorted in an ascending fashion and false otherwise
Since:
1.0

swap

protected abstract void swap(Object dataToSort,
                             int position1,
                             int position2)
Swaps the position of two entries in the provided datastructure. This is an abstract method that needs to be implemented by every extending class.

Parameters:
dataToSort - An Object instance that points to the datastructure in which the entries have to be swapped.
position1 - An integer with the position of the first entry.
position2 - An integer with the position of the second entry.
Since:
1.0

elementAt

protected abstract Object elementAt(Object dataToSort,
                                    int position)
Retrieves an entry from a certain position within the specified datastructure.

Parameters:
dataToSort - An Object instance that points to the datastructure from where the entry has to be retrieved.
position - An integer with the position of the entry that has to be retrieved.
Returns:
An Object instace containing the entry at the specified position.
Since:
1.0

compare

protected abstract int compare(Object element1,
                               Object element2)
Compares the entries, determining which one comes before the other.

Parameters:
element1 - An Object instance containing the first entry.
element2 - An Object instance containing the second entry.
Returns:
0 if the two entries are equals; or

an integer <0 if the first entry comes before the second one; or

an integer >0 if the first entry comes after the second one

Since:
1.0


Copyright © 2001-2007 Uwyn sprl/bvba. All Rights Reserved.