GramKeyGroupComparator extends WritableComparator implements Serializable { @Override public int compare(WritableComparable a, WritableComparable b) { GramKey gka = (GramKey) a; GramKey gkb = (GramKey) b; return WritableComparator.compareBytes(gka.getBytes(), 0, gka.getPrimaryLength(), gkb.getBytes(), 0, gkb.getPrimaryLength()); } GramKeyGroupComparator(); @Override int compare(WritableComparable a, WritableComparable b);  }
@Test public void testComparator() { byte[] foo = new byte[1]; foo[0] = 1; byte[] empty = new byte[0]; GramKey a = new GramKey(new Gram("foo", 1, Gram.Type.HEAD), empty); GramKey b = new GramKey(new Gram("foo", 1, Gram.Type.HEAD), foo); GramKey c = new GramKey(new Gram("foo", 2, Gram.Type.HEAD), empty); GramKey d = new GramKey(new Gram("foo", 1, Gram.Type.TAIL), empty); GramKey e = new GramKey(new Gram("bar", 5, Gram.Type.HEAD), empty); GramKeyGroupComparator cmp = new GramKeyGroupComparator(); assertEquals(0, cmp.compare(a, b)); assertEquals(0, cmp.compare(a, c)); assertTrue(cmp.compare(a, d) < 0); assertTrue(cmp.compare(a, e) > 0); assertTrue(cmp.compare(d, e) > 0); }
@Test public void testComparator() { byte[] foo = new byte[1]; foo[0] = (byte) 1; byte[] empty = new byte[0]; GramKey a = new GramKey(new Gram("foo", 1, Gram.Type.HEAD), empty); GramKey b = new GramKey(new Gram("foo", 1, Gram.Type.HEAD), foo); GramKey c = new GramKey(new Gram("foo", 2, Gram.Type.HEAD), empty); GramKey d = new GramKey(new Gram("foo", 1, Gram.Type.TAIL), empty); GramKey e = new GramKey(new Gram("bar", 5, Gram.Type.HEAD), empty); GramKeyGroupComparator cmp = new GramKeyGroupComparator(); assertEquals(0, cmp.compare(a, b)); assertEquals(0, cmp.compare(a, c)); assertTrue(cmp.compare(a, d) < 0); assertTrue(cmp.compare(a, e) > 0); assertTrue(cmp.compare(d, e) > 0); }