001    package edu.nrao.sss.sort;
002    
003    import java.util.Comparator;
004    
005    /**
006     * A sort key for {@code Double}s (and {@code double}s).
007     * <p/>
008     * The most common way to extend this class is to subclass it into a class
009     * that also implements {@link Comparator}.  The main job of the subclass
010     * is to provide the doubles to this parent class.  Example:
011     * <pre>
012     *   &#x002F;**
013     *    * Sorts teams based on their win / loss percentage.
014     *    *&#x002F;
015     *   public class TeamWinPctKey extends DoubleSortKey
016     *     implements Comparator&lt;Team&gt;
017     *   {
018     *     public int compare(Team t1, Team t2)
019     *     {
020     *       return compareObjects(t1.getWinningPercentage(),
021     *                             t2.getWinningPercentage());
022     *     }
023     *   }</pre>
024     * <p>
025     * Clients of the example <tt>TeamWinPctKey</tt> class are able to configure
026     * that comparator via the {@link #setOrder(SortOrder)} method,
027     * something they cannot do with
028     * the plain <tt>Comparator</tt> interface.  They may then place instances
029     * of this class in a {@link CompoundComparator}.</p>
030     * <p>
031     * <b>Version Info:</b>
032     * <table style="margin-left:2em">
033     *   <tr><td>$Revision: 593 $</td></tr>
034     *   <tr><td>$Date: 2007-05-07 15:54:14 -0600 (Mon, 07 May 2007) $</td></tr>
035     *   <tr><td>$Author: dharland $</td></tr>
036     * </table></p>
037     * 
038     * @author David M. Harland
039     * @since 2007-05-03
040     */
041    public abstract class DoubleSortKey
042      extends SortKey<Double>
043    {
044      /** Helps create a new instance. */
045      protected DoubleSortKey()
046      {
047        super();
048      }
049      
050      /**
051       * Uses the natural ordering of {@code Double}.
052       */
053      protected int compareNatural(Double o1, Double o2)
054      {
055        return o1.compareTo(o2);
056      }
057      
058      /**
059       * Uses the natural ordering of {@code Double}.
060       */
061      protected int compareAscending(Double o1, Double o2)
062      {
063        return compareNatural(o1, o2);
064      }
065    }