com.uwyn.rife.tools
Class SortListComparables

java.lang.Object
  extended by com.uwyn.rife.tools.Sort
      extended by com.uwyn.rife.tools.SortListComparables

public class SortListComparables
extends Sort

Extends the Sort class to implement the features that are needed to sort an List datastructure containing only objects that implement the Comparable interface.

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

Constructor Summary
SortListComparables()
           
 
Method Summary
protected  int compare(Object element1, Object element2)
          Compares the entries, determining which one comes before the other.
protected  Object elementAt(Object dataToSort, int position)
          Retrieves an entry from a certain position within the specified datastructure.
 void sort(List<? extends Comparable> dataToSort)
          Starts the sorting of the entire ArrayList.
 void sort(List<? extends Comparable> dataToSort, boolean ascending)
          Starts the sorting of the entire ArrayList.
protected  void swap(Object dataToSort, int position1, int position2)
          Swaps the position of two entries in the provided datastructure.
 
Methods inherited from class com.uwyn.rife.tools.Sort
quickSort, sort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortListComparables

public SortListComparables()
Method Detail

sort

public final void sort(List<? extends Comparable> dataToSort)
Starts the sorting of the entire ArrayList.

Parameters:
dataToSort - An ArrayList instance that has to be sorted.
Since:
1.0

sort

public final void sort(List<? extends Comparable> dataToSort,
                       boolean ascending)
Starts the sorting of the entire ArrayList.

Parameters:
dataToSort - An ArrayList instance that has to be sorted.
ascending - true of the data has to be sorted in an ascending fashion and false otherwise
Since:
1.0

swap

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

Specified by:
swap in class Sort
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.

elementAt

protected Object elementAt(Object dataToSort,
                           int position)
Description copied from class: Sort
Retrieves an entry from a certain position within the specified datastructure.

Specified by:
elementAt in class Sort
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.

compare

protected int compare(Object element1,
                      Object element2)
Description copied from class: Sort
Compares the entries, determining which one comes before the other.

Specified by:
compare in class Sort
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



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