1 package tim.prune.function.autoplay;
3 import tim.prune.data.DataPoint;
4 import tim.prune.data.Timestamp;
7 * Holds the information about a single point required for the sorting
9 public class PointInfo implements Comparable<PointInfo>
11 /** Timestamp of the point, if any */
12 private Timestamp _timestamp = null;
13 /** Point index in the track */
14 private int _pointIndex = 0;
15 /** Segment flag of point */
16 private boolean _segmentFlag = false;
21 * @param inPoint point from track
22 * @param inIndex index of point in track
24 public PointInfo(DataPoint inPoint, int inIndex)
26 if (inPoint.hasTimestamp())
28 _timestamp = inPoint.getTimestamp();
30 else if (inPoint.getPhoto() != null && inPoint.getPhoto().hasTimestamp())
32 _timestamp = inPoint.getPhoto().getTimestamp();
34 _pointIndex = inIndex;
35 _segmentFlag = inPoint.getSegmentStart();
38 /** @return timestamp */
39 public Timestamp getTimestamp() {
43 /** @return point index */
44 public int getIndex() {
48 /** @return segment flag */
49 public boolean getSegmentFlag() {
54 * Sort two objects by timestamp and if times equal then by point index
56 public int compareTo(PointInfo inOther)
59 final boolean thisHasTime = (_timestamp != null);
60 final boolean otherHasTime = (inOther._timestamp != null);
61 if (thisHasTime && otherHasTime)
63 timeDiff = _timestamp.getMillisecondsSince(inOther._timestamp);
67 timeDiff = -1; // points without time to the end
69 else if (otherHasTime)
73 // If the times are equal (or both missing) then use the point index
75 return _pointIndex - inOther._pointIndex;
77 // Otherwise, compare by time
78 return (timeDiff < 0 ? -1 : 1);
82 public boolean equals(Object inOther)
84 if (inOther == null) return false;
87 PointInfo other = (PointInfo) inOther;
88 if (_pointIndex != other._pointIndex) return false;
89 final boolean thisHasTime = (_timestamp != null);
90 final boolean otherHasTime = (other._timestamp != null);
91 if (thisHasTime != otherHasTime) {return false;}
92 if (!thisHasTime && !otherHasTime) {return true;}
93 return _timestamp.isEqual(other._timestamp);
95 catch (ClassCastException cce) {}