]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - tim/prune/data/sort/WaypointComparer.java
Moved source into separate src directory due to popular request
[GpsPrune.git] / tim / prune / data / sort / WaypointComparer.java
diff --git a/tim/prune/data/sort/WaypointComparer.java b/tim/prune/data/sort/WaypointComparer.java
deleted file mode 100644 (file)
index b1c3e2a..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-package tim.prune.data.sort;
-
-import java.util.Comparator;
-
-import tim.prune.data.DataPoint;
-
-
-/**
- * Class for comparing waypoints to sort them by name or timestamp
- */
-public class WaypointComparer implements Comparator<DataPoint>
-{
-       /** Sort mode */
-       private SortMode _sortMode;
-
-
-       /**
-        * Constructor
-        * @param inMode sort mode
-        */
-       public WaypointComparer(SortMode inMode)
-       {
-               _sortMode = inMode;
-       }
-
-       /**
-        * Main compare method
-        */
-       public int compare(DataPoint inP1, DataPoint inP2)
-       {
-               if (inP2 == null || !inP2.isWaypoint()) return -1; // all nulls at end
-               if (inP1 == null || !inP1.isWaypoint()) return 1;
-
-               // Sort by time, if requested
-               int result = 0;
-               if (_sortMode == SortMode.SORTBY_TIME) {
-                       result = compareTimes(inP1, inP2);
-               }
-               // check names if names requested or if times didn't work
-               if (result == 0) {
-                       result = inP1.getWaypointName().compareTo(inP2.getWaypointName());
-               }
-               // names and times equal, try longitude
-               if (result == 0) {
-                       result = inP1.getLongitude().getDouble() > inP2.getLongitude().getDouble() ? 1 : -1;
-               }
-               // and latitude
-               if (result == 0) {
-                       result = inP1.getLatitude().getDouble() > inP2.getLatitude().getDouble() ? 1 : -1;
-               }
-               return result;
-       }
-
-       /**
-        * Compare the timestamps of the two waypoints
-        * @param inP1 first point
-        * @param inP2 second point
-        * @return compare value (-1,0,1)
-        */
-       private int compareTimes(DataPoint inP1, DataPoint inP2)
-       {
-               // Points might not have timestamps
-               if (inP1.hasTimestamp() && !inP2.hasTimestamp()) return 1;
-               if (!inP1.hasTimestamp() && inP2.hasTimestamp()) return -1;
-               if (inP1.hasTimestamp() && inP2.hasTimestamp())
-               {
-                       // Compare the timestamps
-                       long secDiff = inP1.getTimestamp().getMillisecondsSince(inP2.getTimestamp());
-                       return (secDiff<0?-1:(secDiff==0?0:1));
-               }
-               // neither has a timestamp
-               return 0;
-       }
-}