edu.nrao.sss.sort
Class IntSortKey

java.lang.Object
  extended by edu.nrao.sss.sort.SortKey<Integer>
      extended by edu.nrao.sss.sort.IntSortKey
All Implemented Interfaces:
Orderable
Direct Known Subclasses:
ReflectiveIntSortKey

public abstract class IntSortKey
extends SortKey<Integer>

A sort key for Integerss (and ints).

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 integers to this parent class. Example:

   /**
    * Sorts engines based on the number of cylinders they have.
    */
   public class EngineCylinderCountKey extends IntSortKey
     implements Comparator<Engine>
   {
     public int compare(Engine e1, Engine e2)
     {
       return compareObjects(e1.getCylinders().size(),
                             e2.getCylinders().size());
     }
   }

Clients of the example EngineCylinderCountKey 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-07
Author:
David M. Harland

Constructor Summary
protected IntSortKey()
          Helps create a new instance.
 
Method Summary
protected  int compareAscending(Integer o1, Integer o2)
          Uses the natural ordering of Integer.
protected  int compareNatural(Integer o1, Integer o2)
          Uses the natural ordering of Integer.
 
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

IntSortKey

protected IntSortKey()
Helps create a new instance.

Method Detail

compareNatural

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

Specified by:
compareNatural in class SortKey<Integer>

compareAscending

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

Specified by:
compareAscending in class SortKey<Integer>


Copyright © 2009. All Rights Reserved.