001    package edu.nrao.sss.measure;
002    
003    import java.util.Comparator;
004    
005    import edu.nrao.sss.sort.CompoundComparator;
006    import edu.nrao.sss.sort.Orderable;
007    import edu.nrao.sss.sort.SortKey;
008    import edu.nrao.sss.sort.SortOrder;
009    
010    /**
011     * A {@link SortKey sort key} and {@link Comparator comparator} that works with
012     * {@link EquatorialArc equatorial arcs}, such as {@link Latitude latitude} or
013     * {@link Longitude longitude}.
014     * <p>
015     * Because this class is a {@link SortKey}, you may configure its instances with
016     * a particular {@code SortOrder}.  This class adds additional configurability
017     * by letting clients decide to compare angles as they are or, instead, in
018     * normalized form.  You may place instances of this
019     * class in a {@link CompoundComparator}.</p>
020     * <p>
021     * <b>Version Info:</b>
022     * <table style="margin-left:2em">
023     *   <tr><td>$Revision: 1707 $</td></tr>
024     *   <tr><td>$Date: 2008-11-14 10:23:59 -0700 (Fri, 14 Nov 2008) $</td></tr>
025     *   <tr><td>$Author: dharland $</td></tr>
026     * </table></p>
027     * 
028     * @author David M. Harland
029     * @since 2007-05-07
030     */
031    public class EquatorialArcSortKey<A extends EquatorialArc<A>>
032      implements Orderable, Comparator<A>
033    {
034      private AngleSortKey angleSorter;
035      
036      /** Creates a new instance. */
037      public EquatorialArcSortKey()
038      {
039        angleSorter = new AngleSortKey();
040      }
041      
042      /* (non-Javadoc)
043       * @see edu.nrao.sss.sort.Orderable#setOrder(edu.nrao.sss.sort.SortOrder)
044       */
045      public void setOrder(SortOrder newOrder)
046      {
047        angleSorter.setOrder(newOrder);
048      }
049      
050      /* (non-Javadoc)
051       * @see edu.nrao.sss.sort.Orderable#getOrder()
052       */
053      public SortOrder getOrder()
054      {
055        return angleSorter.getOrder();
056      }
057      
058      /* (non-Javadoc)
059       * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
060       */
061      public int compare(A a1, A a2)
062      {
063        Angle angle1 = (a1 == null) ? null : a1.getAngle();
064        Angle angle2 = (a2 == null) ? null : a2.getAngle();
065        
066        return angleSorter.compare(angle1, angle2);
067      }
068    }