Tuple implements Comparable<Tuple> { public int compareTo(Tuple other) { if (this.score == other.getScore() || Arrays.equals(this.element, other.element)) return 0; else return this.score < other.getScore() ? -1 : 1; } Tuple(String element, Double score);  Tuple(byte[] element, Double score); int hashCode(); boolean equals(Object obj); int compareTo(Tuple other); String getElement(); byte[] getBinaryElement(); double getScore(); String toString();  }
@Test public void testCompareTo() { Tuple t1 = new Tuple("foo", 1.0); Tuple t2 = new Tuple("bar", 1.0); Tuple t3 = new Tuple("elem3", 2.0); Tuple t4 = new Tuple("foo", 10.0); assertEquals(0, t1.compareTo(t2)); assertEquals(0, t2.compareTo(t1)); assertEquals(-1, t1.compareTo(t3)); assertEquals(1, t3.compareTo(t1)); assertEquals(0, t1.compareTo(t4)); assertEquals(0, t4.compareTo(t1)); }