UniqueName implements Comparable<UniqueName> { @Override public int compareTo(UniqueName other) { if (this == other) { return 0; } int returnCode = name.compareTo(other.name); if (returnCode != 0) { return returnCode; } return ((Integer) id).compareTo(other.id); } UniqueName(ConcurrentMap<String, Boolean> map, String name, Object... args); protected  UniqueName(String name); final String name(); final int id(); @Override final int hashCode(); @Override final boolean equals(Object o); @Override int compareTo(UniqueName other); @Override String toString();  }
@Test public void testCompareNames() { UniqueName one = registerName("One"); UniqueName two = registerName("Two"); ConcurrentMap<String, Boolean> mapTwo = PlatformDependent.newConcurrentHashMap(); UniqueName three = new UniqueName(mapTwo, "One"); assertSame(one.compareTo(one), 0); assertSame(one.compareTo(two), -5); assertSame(one.compareTo(three), -1); assertSame(three.compareTo(one), 1); }