]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/TimeIndexPair.java
Version 11, August 2010
[GpsPrune.git] / tim / prune / correlate / TimeIndexPair.java
1 package tim.prune.correlate;
2
3 /**
4  * Simple class to hold a time and an index.
5  * Used in a TreeSet for calculating median time difference
6  */
7 public class TimeIndexPair implements Comparable<TimeIndexPair>
8 {
9         /** Time as long */
10         private long _time = 0L;
11         /** Index as int */
12         private int _index = 0;
13
14
15         /**
16          * Constructor
17          * @param inTime time as long
18          * @param inIndex index as int
19          */
20         public TimeIndexPair(long inTime, int inIndex)
21         {
22                 _time = inTime;
23                 _index = inIndex;
24         }
25
26
27         /**
28          * @return the index
29          */
30         public int getIndex()
31         {
32                 return _index;
33         }
34
35
36         /**
37          * Compare two TimeIndexPair objects
38          * @see java.lang.Comparable#compareTo(java.lang.Object)
39          */
40         public int compareTo(TimeIndexPair inOther)
41         {
42                 int compare = (int) (_time - inOther._time);
43                 if (compare == 0) {compare = _index - inOther._index;}
44                 return compare;
45         }
46
47         /**
48          * Override equals method to match compareTo
49          */
50         public boolean equals(Object inOther)
51         {
52                 if (inOther instanceof TimeIndexPair) {
53                         TimeIndexPair otherPair = (TimeIndexPair) inOther;
54                         return _time == otherPair._time;
55                 }
56                 return false;
57         }
58 }