@Test public void test_simple() { byte[] key = "test".getBytes(); byte[] nextKey = RowKeyUtil.calculateTheClosestNextRowKeyForPrefix(key); Assert.assertEquals((byte) (key[key.length - 1] + 1), nextKey[key.length - 1]); }
public static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix) { int offset = rowKeyPrefix.length; while (offset > 0) { if (rowKeyPrefix[offset - 1] != (byte) 0xFF) { break; } offset--; } if (offset == 0) { return EMPTY_KEY; } byte[] newStopRow = Arrays.copyOfRange(rowKeyPrefix, 0, offset); newStopRow[newStopRow.length - 1]++; return newStopRow; }
RowKeyUtil { public static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix) { int offset = rowKeyPrefix.length; while (offset > 0) { if (rowKeyPrefix[offset - 1] != (byte) 0xFF) { break; } offset--; } if (offset == 0) { return EMPTY_KEY; } byte[] newStopRow = Arrays.copyOfRange(rowKeyPrefix, 0, offset); newStopRow[newStopRow.length - 1]++; return newStopRow; } }
RowKeyUtil { public static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix) { int offset = rowKeyPrefix.length; while (offset > 0) { if (rowKeyPrefix[offset - 1] != (byte) 0xFF) { break; } offset--; } if (offset == 0) { return EMPTY_KEY; } byte[] newStopRow = Arrays.copyOfRange(rowKeyPrefix, 0, offset); newStopRow[newStopRow.length - 1]++; return newStopRow; }  }
RowKeyUtil { public static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix) { int offset = rowKeyPrefix.length; while (offset > 0) { if (rowKeyPrefix[offset - 1] != (byte) 0xFF) { break; } offset--; } if (offset == 0) { return EMPTY_KEY; } byte[] newStopRow = Arrays.copyOfRange(rowKeyPrefix, 0, offset); newStopRow[newStopRow.length - 1]++; return newStopRow; }  static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix); }
RowKeyUtil { public static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix) { int offset = rowKeyPrefix.length; while (offset > 0) { if (rowKeyPrefix[offset - 1] != (byte) 0xFF) { break; } offset--; } if (offset == 0) { return EMPTY_KEY; } byte[] newStopRow = Arrays.copyOfRange(rowKeyPrefix, 0, offset); newStopRow[newStopRow.length - 1]++; return newStopRow; }  static byte[] calculateTheClosestNextRowKeyForPrefix(byte[] rowKeyPrefix);  }