@Test public void compareToTest() { List<Offset> offsets = new ArrayList<>(); offsets.add(new Offset("0_0", 0)); offsets.add(new Offset("0_0", 1)); offsets.add(new Offset("0_1", 0)); offsets.add(new Offset("0_1", 1)); offsets.add(new Offset("1_0", 0)); offsets.add(new Offset("1_0", 1)); offsets.add(new Offset("2_0", 0)); offsets.add(new Offset("3_0", 1)); offsets.add(new Offset("10_0", 0)); offsets.add(new Offset("21_0", 0)); for (int i = 0; i < offsets.size(); i++) { for (int j = 0; j < offsets.size(); j++) { int expectCompare = i == j ? 0 : i > j ? 1 : -1; assertEquals("Unexpected value on compare", expectCompare, offsets.get(i).compareTo(offsets.get(j))); assertEquals("Unexpected value on compare", -1 * expectCompare, offsets.get(j).compareTo(offsets.get(i))); } } }
@Override public int compareTo(Offset o) { int compare = LogSegmentNameHelper.COMPARATOR.compare(name, o.name); return compare == 0 ? Long.compare(offset, o.offset) : compare; }
Offset implements Comparable<Offset> { @Override public int compareTo(Offset o) { int compare = LogSegmentNameHelper.COMPARATOR.compare(name, o.name); return compare == 0 ? Long.compare(offset, o.offset) : compare; } }
Offset implements Comparable<Offset> { @Override public int compareTo(Offset o) { int compare = LogSegmentNameHelper.COMPARATOR.compare(name, o.name); return compare == 0 ? Long.compare(offset, o.offset) : compare; } Offset(String name, long offset); }
Offset implements Comparable<Offset> { @Override public int compareTo(Offset o) { int compare = LogSegmentNameHelper.COMPARATOR.compare(name, o.name); return compare == 0 ? Long.compare(offset, o.offset) : compare; } Offset(String name, long offset); static Offset fromBytes(DataInputStream stream); String getName(); long getOffset(); @Override int compareTo(Offset o); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
Offset implements Comparable<Offset> { @Override public int compareTo(Offset o) { int compare = LogSegmentNameHelper.COMPARATOR.compare(name, o.name); return compare == 0 ? Long.compare(offset, o.offset) : compare; } Offset(String name, long offset); static Offset fromBytes(DataInputStream stream); String getName(); long getOffset(); @Override int compareTo(Offset o); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }