X-Git-Url: http://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Fcorrelate%2FTimeIndexPair.java;fp=src%2Ftim%2Fprune%2Fcorrelate%2FTimeIndexPair.java;h=23401120755ca0a96fdecf30ce3cf7be1cbd5929;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/correlate/TimeIndexPair.java b/src/tim/prune/correlate/TimeIndexPair.java new file mode 100644 index 0000000..2340112 --- /dev/null +++ b/src/tim/prune/correlate/TimeIndexPair.java @@ -0,0 +1,58 @@ +package tim.prune.correlate; + +/** + * Simple class to hold a time and an index. + * Used in a TreeSet for calculating median time difference + */ +public class TimeIndexPair implements Comparable +{ + /** Time as long */ + private long _time = 0L; + /** Index as int */ + private int _index = 0; + + + /** + * Constructor + * @param inTime time as long + * @param inIndex index as int + */ + public TimeIndexPair(long inTime, int inIndex) + { + _time = inTime; + _index = inIndex; + } + + + /** + * @return the index + */ + public int getIndex() + { + return _index; + } + + + /** + * Compare two TimeIndexPair objects + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int compareTo(TimeIndexPair inOther) + { + int compare = (int) (_time - inOther._time); + if (compare == 0) {compare = _index - inOther._index;} + return compare; + } + + /** + * Override equals method to match compareTo + */ + public boolean equals(Object inOther) + { + if (inOther instanceof TimeIndexPair) { + TimeIndexPair otherPair = (TimeIndexPair) inOther; + return _time == otherPair._time; + } + return false; + } +}