1 package tim.prune.data;
4 * Class to provide checking functions
6 public abstract class Checker
10 * Check if a given track is doubled, so that each point is given twice,
11 * once as waypoint and again as track point
12 * @param inTrack track to check
13 * @return true if track is doubled, false otherwise
15 public static boolean isDoubledTrack(Track inTrack)
17 // Check for empty track
18 if (inTrack == null || inTrack.getNumPoints() < 2) {return false;}
19 // Check for non-even number of points
20 final int numPoints = inTrack.getNumPoints();
21 if (numPoints % 2 != 0) {return false;}
22 // Loop through first half of track
23 final int halfNum = numPoints / 2;
24 for (int i=0; i<halfNum; i++)
26 DataPoint firstPoint = inTrack.getPoint(i);
27 DataPoint secondPoint = inTrack.getPoint(i + halfNum);
28 if (!firstPoint.getLatitude().equals(secondPoint.getLatitude())
29 || !firstPoint.getLongitude().equals(secondPoint.getLongitude())) {
33 // Passed the test, so contents must all be doubled
38 * Find the index of the next segment start after the given index
39 * @param inTrack track object
40 * @param inIndex current index
41 * @return index of next segment start
43 public static int getNextSegmentStart(Track inTrack, int inIndex)
46 DataPoint point = null;
47 while ((point=inTrack.getPoint(i)) != null && (point.isWaypoint() || !point.getSegmentStart())) {
50 return Math.min(i, inTrack.getNumPoints()-1);
54 * Find the index of the previous segment start before the given index
55 * @param inTrack track object
56 * @param inIndex current index
57 * @return index of previous segment start
59 public static int getPreviousSegmentStart(Track inTrack, int inIndex)
62 DataPoint point = null;
63 while ((point=inTrack.getPoint(i)) != null && (point.isWaypoint() || !point.getSegmentStart())) {
66 // Have we gone past the beginning of the track?
68 // count forwards past the waypoints if necessary
69 while ((point=inTrack.getPoint(i)) != null && point.isWaypoint()) {
76 * Find the index of the last track point in the current segment
77 * @param inTrack track object
78 * @param inIndex current index
79 * @return index of next segment end
81 public static int getNextSegmentEnd(Track inTrack, int inIndex)
83 // First, go to start of following segment, or the end of the track
84 int i = getNextSegmentStart(inTrack, inIndex);
85 // If it's the next segment, subtract one
86 DataPoint point = inTrack.getPoint(i);
87 if (point == null || point.getSegmentStart())
91 // Now we may be on a waypoint, so count back to get the last track point
92 while ((point=inTrack.getPoint(i)) != null && point.isWaypoint()) {
95 return Math.min(i, inTrack.getNumPoints()-1);
100 * @param inTrack track object
101 * @return true if there is at least one waypoint with a timestamp
103 public static boolean haveWaypointsGotTimestamps(Track inTrack)
107 for (int i=0; i<inTrack.getNumPoints(); i++)
109 DataPoint p = inTrack.getPoint(i);
110 if (p != null && p.isWaypoint() && p.hasTimestamp())