MetricId implements Comparable<MetricId> { @Override public int compareTo(MetricId o) { if (o == null) { return -1; } if (this == o) { return 0; } final int h = Integer.compare(hash, o.hash); if (h != 0) { return h; } final int k = compareKey(key, o.getKey()); if (k != 0) { return k; } return compareTags(tags.entrySet(), o.tags.entrySet()); } MetricId();  MetricId(String key);  MetricId(String key, Map<String, String> tags); @Deprecated @VisibleForTesting  MetricId(String key, SortedMap<String, String> tags); private  MetricId(String key, SortedMap<String, String> tags, boolean isAlreadyUnmodifiable); String getKey(); Map<String, String> getTags(); MetricId resolve(final String part); MetricId tagged(Map<String, String> add); MetricId tagged(String... pairs); MetricId tagged(String k1, String v1); MetricId tagged(String k1, String v1, String k2, String v2); MetricId tagged(String k1, String v1, String k2, String v2, String k3, String v3); static MetricId join(MetricId... parts); static MetricId build(final String... parts); @Override String toString(); @Override int hashCode(); @Override boolean equals(Object obj); @Override int compareTo(MetricId o); static final String SEPARATOR; static final SortedMap<String, String> EMPTY_TAGS; static final MetricId EMPTY; }
@Test public void testCompareTo() { final MetricId a = MetricId.EMPTY.tagged("foo", "bar"); final MetricId b = MetricId.EMPTY.tagged("foo", "baz"); final MetricId c = MetricId.EMPTY.tagged("foo", null); assertTrue(a.compareTo(b) != 0); assertTrue(b.compareTo(a) != 0); assertTrue(c.compareTo(a) != 0); assertTrue(a.compareTo(c) != 0); assertEquals(0, b.compareTo(b)); assertEquals(0, c.compareTo(c)); assertTrue(b.resolve("key").compareTo(b) != 0); assertTrue(b.compareTo(b.resolve("key")) != 0); assertTrue(c.resolve("key").compareTo(c) != 0); assertTrue(c.compareTo(c.resolve("key")) != 0); }