* Simple class to hold a time and an index.
* Used in a TreeSet for calculating median time difference
*/
-public class TimeIndexPair implements Comparable
+public class TimeIndexPair implements Comparable<TimeIndexPair>
{
/** Time as long */
private long _time = 0L;
* Compare two TimeIndexPair objects
* @see java.lang.Comparable#compareTo(java.lang.Object)
*/
- public int compareTo(Object inOther)
+ public int compareTo(TimeIndexPair inOther)
{
- TimeIndexPair other = (TimeIndexPair) inOther;
- return (int) (_time - other._time);
+ 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;
}
}