KeyComparator implements Comparator<CKeyValue> { @Override public int compare(CKeyValue arg0, CKeyValue arg1) { LexicographicBytesComparator comparator = LexicographicBytesComparator.INSTANCE; int compare = comparator.compare(arg0.getRowId(), arg1.getRowId()); if (compare == 0) { compare = comparator.compare(arg0.getFamily(), arg1.getFamily()); if (compare == 0) compare = comparator.compare(arg0.getQualifier(), arg1.getQualifier()); } return compare; } private  KeyComparator(); @Override int compare(CKeyValue arg0, CKeyValue arg1); static final Comparator<? super CKeyValue> INSTANCE; }
@Test public void testKeyCompare() throws Exception { Comparator<? super CKeyValue> comparator = KeyComparator.INSTANCE; CKeyValue one = new CKeyValue(new byte[0]); CKeyValue two = new CKeyValue(new byte[1]); int compare = comparator.compare(one, two); assertTrue(compare < 0); one = new CKeyValue(new byte[] { 1 }); two = new CKeyValue(new byte[] { 1, 2 }); compare = comparator.compare(one, two); assertTrue(compare < 0); one = new CKeyValue(new byte[] { 2 }); two = new CKeyValue(new byte[] { 1, 2 }); compare = comparator.compare(one, two); assertTrue(compare > 0); compare = comparator.compare(two, two); assertEquals(0, compare); }
@Test public void testFullKeysCompare() throws Exception { Comparator<? super CKeyValue> comparator = KeyComparator.INSTANCE; CKeyValue one = new CKeyValue(new byte[0], new byte[0], new byte[] { 2 }); CKeyValue two = new CKeyValue(new byte[1], new byte[1], new byte[] { 1 }); int compare = comparator.compare(one, two); assertTrue(compare < 0); one = new CKeyValue(new byte[] { 1 }, new byte[] { 1 }, new byte[] { 1 }); two = new CKeyValue(new byte[] { 1, 2 }, new byte[] { 1, 2 }, new byte[] { 1 }); compare = comparator.compare(one, two); assertTrue(compare < 0); one = new CKeyValue(new byte[] { 1, 2 }, new byte[] { 2 }, new byte[] { 1 }); two = new CKeyValue(new byte[] { 1, 2 }, new byte[1], new byte[] { 1 }); compare = comparator.compare(one, two); assertTrue(compare > 0); compare = comparator.compare(two, two); assertEquals(0, compare); }