ByteKey implements Comparable<ByteKey>, Serializable { @Override public int compareTo(@Nonnull ByteKey other) { checkNotNull(other, "other"); ByteIterator thisIt = value.iterator(); ByteIterator otherIt = other.value.iterator(); while (thisIt.hasNext() && otherIt.hasNext()) { int cmp = (thisIt.nextByte() & 0xff) - (otherIt.nextByte() & 0xff); if (cmp != 0) { return cmp; } } return value.size() - other.value.size(); } private  ByteKey(ByteString value); static ByteKey copyFrom(ByteBuffer value); static ByteKey copyFrom(byte[] bytes); static ByteKey of(int... bytes); ByteBuffer getValue(); byte[] getBytes(); boolean isEmpty(); @Override int compareTo(@Nonnull ByteKey other); @Override String toString(); @Override boolean equals(@Nullable Object o); @Override int hashCode(); static final ByteKey EMPTY; }
@Test public void testCompareToExhaustive() { for (int i = 0; i < TEST_KEYS.length; ++i) { for (int j = 0; j < TEST_KEYS.length; ++j) { ByteKey left = TEST_KEYS[i]; ByteKey right = TEST_KEYS[j]; int cmp = left.compareTo(right); if (i < j && !(cmp < 0)) { fail( String.format( "Expected that cmp(%s, %s) < 0, got %d [i=%d, j=%d]", left, right, cmp, i, j)); } else if (i == j && !(cmp == 0)) { fail( String.format( "Expected that cmp(%s, %s) == 0, got %d [i=%d, j=%d]", left, right, cmp, i, j)); } else if (i > j && !(cmp > 0)) { fail( String.format( "Expected that cmp(%s, %s) > 0, got %d [i=%d, j=%d]", left, right, cmp, i, j)); } } } }