]> gitweb.fperrin.net Git - GpsPrune.git/blob - tim/prune/correlate/TimeIndexPair.java
775b151ac32e92005ae8ca005ba1b8e67ebf5aba
[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                 return (int) (_time - inOther._time);
43         }
44
45         /**
46          * Override equals method to match compareTo
47          */
48         public boolean equals(Object inOther)
49         {
50                 if (inOther instanceof TimeIndexPair) {
51                         TimeIndexPair otherPair = (TimeIndexPair) inOther;
52                         return _time == otherPair._time;
53                 }
54                 return false;
55         }
56 }