edu.nrao.sss.sort
Class SortKey<T>

java.lang.Object
  extended by edu.nrao.sss.sort.SortKey<T>
All Implemented Interfaces:
Orderable
Direct Known Subclasses:
DoubleSortKey, EnumSortKey, IntSortKey, StringSortKey

public abstract class SortKey<T>
extends Object
implements Orderable

A single sorting key.

Version Info:

$Revision: 593 $
$Date: 2007-05-07 15:54:14 -0600 (Mon, 07 May 2007) $
$Author: dharland $

Since:
2007-05-03
Author:
David M. Harland

Constructor Summary
protected SortKey()
          Helps create a new key with a natural order.
 
Method Summary
protected abstract  int compareAscending(T o1, T o2)
          Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in ascending order.
protected abstract  int compareNatural(T o1, T o2)
          Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in natural order.
protected  int compareObjects(T o1, T o2)
          Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in this key's current order.
protected  int compareObjects(T o1, T o2, SortOrder ordering)
          Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in according to t he given sort order.
 SortOrder getOrder()
          Returns the sort order.
protected  int nullOrdering(T o1, T o2)
          Handles comparisons when exactly one of the two objects is null.
protected  boolean objectsAreEqual(Object o1, Object o2)
          Returns true if the two objects are equal.
 void setOrder(SortOrder newOrder)
          Sets the order to newOrder.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortKey

protected SortKey()
Helps create a new key with a natural order.

Method Detail

setOrder

public void setOrder(SortOrder newOrder)
Description copied from interface: Orderable
Sets the order to newOrder.

Implementing classes should handle a null parameter in some way other than merely saving it and waiting for a downstream NullPointerException. Typical responses would be to replace null with some valid value, such as SortOrder.NATURAL, or to throw an IllegalArgumentException.

Specified by:
setOrder in interface Orderable
Parameters:
newOrder - the new order for sorting.

getOrder

public SortOrder getOrder()
Description copied from interface: Orderable
Returns the sort order.

Implementing classes should guarantee that the returned value will never be null.

Specified by:
getOrder in interface Orderable
Returns:
the sort order.

compareObjects

protected int compareObjects(T o1,
                             T o2)
Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in this key's current order.


compareObjects

protected int compareObjects(T o1,
                             T o2,
                             SortOrder ordering)
Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in according to t he given sort order.

This method is called by compareObjects(T o1, T o2).


compareNatural

protected abstract int compareNatural(T o1,
                                      T o2)
Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in natural order.


compareAscending

protected abstract int compareAscending(T o1,
                                        T o2)
Returns a number less than zero, zero, or greater than zero as o1 is before, coincident with, or after o2 when sorted in ascending order.


objectsAreEqual

protected boolean objectsAreEqual(Object o1,
                                  Object o2)
Returns true if the two objects are equal. This method is used by compareObjects(Object, Object).


nullOrdering

protected int nullOrdering(T o1,
                           T o2)
Handles comparisons when exactly one of the two objects is null. For ascending and natural sorts, null objects are placed at the end of the line. For descending sorts they are placed at the beginning. This method is used by compareObjects(Object, Object).



Copyright © 2009. All Rights Reserved.