DirectBufferComparator implements Comparator<DirectBuffer> { @Override public int compare(DirectBuffer o1, DirectBuffer o2) { return compareTo(o1, 0, o1.capacity(), o2, 0, o2.capacity()); }  @Override int compare(DirectBuffer o1, DirectBuffer o2); static Comparator<byte[]> byteArrayComparator(); static int compareTo(byte[] key, byte[] stop); static boolean within(byte[] key, byte[] start, byte[] stop); static int compareTo(DirectBuffer key, DirectBuffer stop); static int compareTo(DirectBuffer buffer1, int offset1, int length1,
                              DirectBuffer buffer2, int offset2, int length2); static int compare(byte a, byte b); static int toInt(byte value); static final int LONG_BYTES; }
@Test public void testLessThan8bytes() { assertThat(compare(key(0, 0), stop()), is(0)); assertThat(compare(key(0, 0), stop(0, 0)), is(0)); assertThat(compare(key(0, 0), stop(0 )), is(0)); assertThat(compare(key(0), stop(0, 0)), is(-1)); assertThat(compare(key(0), stop(1, 0)), is(-1)); assertThat(compare(key(0), stop(1 )), is(-1)); assertThat(compare(key(1, 0), stop(0)), is(1)); assertThat(compare(key(0, 1), stop(1 )), is(-1)); }
@Test public void testMoreThan8bytes() { assertThat(compare(key(0,0,0,0,0,0,0,0), stop(0,0,0,0,0,0,0,0)), is(0)); assertThat(compare(key(0,0,0,0,0,0,0,0), stop(1,0,0,0,0,0,0,0)), is(-1)); assertThat(compare(key(0,0,0,0,0,0,0,0), stop(0,0,0,0,0,0,0)), is(0)); assertThat(compare(key(0,0,0,0,0,0,0,0), stop(0,1,0,0,0,0,0,0)), is(-1)); assertThat(compare(key(0,0,0,0,0,0,0,0), stop(0,0,0,0,0,0,0,0)), is(0)); assertThat(compare(key(0,0,0,0,0,0,0,0), stop(0,0,0,0,0,0,0,0)), is(0)); assertThat(compare(key(1,0,0,0,0,0,0,0), stop(1,0,0,0,0,0,0)), is(0)); assertThat(compare(key(0,0,0,0,0,0,0,0), stop(1,0,0,0,0,0,0)), is(-1)); assertThat(compare(key(0,1,0,0,0,0,0,0), stop(0,0,0,0,0,0,0,0)), is(1)); }