edu.nrao.sss.sort
Class DoubleSortKey

java.lang.Object
  extended by edu.nrao.sss.sort.SortKey<Double>
      extended by edu.nrao.sss.sort.DoubleSortKey
All Implemented Interfaces:
Orderable
Direct Known Subclasses:
AngleSortKey, ReflectiveDoubleSortKey

public abstract class DoubleSortKey
extends SortKey<Double>

A sort key for Doubles (and doubles).

The most common way to extend this class is to subclass it into a class that also implements Comparator. The main job of the subclass is to provide the doubles to this parent class. Example:

   /**
    * Sorts teams based on their win / loss percentage.
    */
   public class TeamWinPctKey extends DoubleSortKey
     implements Comparator<Team>
   {
     public int compare(Team t1, Team t2)
     {
       return compareObjects(t1.getWinningPercentage(),
                             t2.getWinningPercentage());
     }
   }

Clients of the example TeamWinPctKey class are able to configure that comparator via the SortKey.setOrder(SortOrder) method, something they cannot do with the plain Comparator interface. They may then place instances of this class in a CompoundComparator.

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 DoubleSortKey()
          Helps create a new instance.
 
Method Summary
protected  int compareAscending(Double o1, Double o2)
          Uses the natural ordering of Double.
protected  int compareNatural(Double o1, Double o2)
          Uses the natural ordering of Double.
 
Methods inherited from class edu.nrao.sss.sort.SortKey
compareObjects, compareObjects, getOrder, nullOrdering, objectsAreEqual, setOrder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DoubleSortKey

protected DoubleSortKey()
Helps create a new instance.

Method Detail

compareNatural

protected int compareNatural(Double o1,
                             Double o2)
Uses the natural ordering of Double.

Specified by:
compareNatural in class SortKey<Double>

compareAscending

protected int compareAscending(Double o1,
                               Double o2)
Uses the natural ordering of Double.

Specified by:
compareAscending in class SortKey<Double>


Copyright © 2009. All Rights Reserved.