class ByteArrayComparator implements Comparator<byte[]> {

    @Override
    public int compare(byte[] o1, byte[] o2) {
	for (int i = 0; i < Math.min(o1.length, o2.length); i++) {
	    if (o1[i] != o2[i]) {
		return (o1[i] & 0xFF) - (o2[i] & 0xFF);
	    }
	}
	if (o1.length == o2.length) {
	    return 0;
	} else if (o1.length < o2.length) {
	    return -1;
	} else {
	    return +1;
	}
    }

}

class ByteArrayComparatorTest {

    private static final ByteArrayComparator comparator;

    @Test
    public void testGreater() {

	assertEquals(1, comparator.compare(new byte[] { 1 }, new byte[] {}));
	assertEquals(1, comparator.compare(new byte[] { 1, 1 }, new byte[] { 1 }));
	assertEquals(1, comparator.compare(new byte[] { 1, 1, 1 }, new byte[] { 1, 1 }));

	assertEquals(1, comparator.compare(new byte[] { 2 }, new byte[] { 1 }));
	assertEquals(1, comparator.compare(new byte[] { 1, 2 }, new byte[] { 1, 1 }));
	assertEquals(1, comparator.compare(new byte[] { 1, 1, 2 }, new byte[] { 1, 1, 1 }));
    }

}