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 == 1) {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.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.getSegmentStart()) {
66 return Math.max(i, 0);