ByteKey implements Comparable<ByteKey>, Serializable { @Override public boolean equals(@Nullable Object o) { if (o == this) { return true; } if (!(o instanceof ByteKey)) { return false; } ByteKey other = (ByteKey) o; return (other.value.size() == value.size()) && this.compareTo(other) == 0; } 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 testEquals() { 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]; boolean eq = left.equals(right); if (i == j) { assertTrue(String.format("Expected that %s is equal to itself.", left), eq); assertTrue( String.format("Expected that %s is equal to a copy of itself.", left), left.equals(ByteKey.copyFrom(right.getValue()))); } else { assertFalse(String.format("Expected that %s is not equal to %s", left, right), eq); } } } }