@Override
  public int compareTo(@Nonnull ByteKey other) {
    checkNotNull(other, "other");
    ByteIterator thisIt = value.iterator();
    ByteIterator otherIt = other.value.iterator();
    while (thisIt.hasNext() && otherIt.hasNext()) {
      // (byte & 0xff) converts [-128,127] bytes to [0,255] ints.
      int cmp = (thisIt.nextByte() & 0xff) - (otherIt.nextByte() & 0xff);
      if (cmp != 0) {
        return cmp;
      }
    }
    // If we get here, the prefix of both arrays is equal up to the shorter array. The array with
    // more bytes is larger.
    return value.size() - other.value.size();
  }
@Test
  public void testCompareToExhaustive() {
    // Verify that the comparison gives the correct result for all values in both directions.
    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));
        }
      }
    }
  }