ByteKeyRangeTracker extends RestrictionTracker<ByteKeyRange, ByteKey> implements HasProgress { @Override public boolean tryClaim(ByteKey key) { if (key.isEmpty()) { checkArgument( lastAttemptedKey == null || !lastAttemptedKey.isEmpty(), "Trying to claim key %s while last attempted key was %s", key, lastAttemptedKey); lastAttemptedKey = key; return false; } checkArgument( lastAttemptedKey == null || key.compareTo(lastAttemptedKey) > 0, "Trying to claim key %s while last attempted key was %s", key, lastAttemptedKey); checkArgument( key.compareTo(range.getStartKey()) > -1, "Trying to claim key %s before start of the range %s", key, range); lastAttemptedKey = key; if (!range.getEndKey().isEmpty() && key.compareTo(range.getEndKey()) > -1) { return false; } lastClaimedKey = key; return true; } private  ByteKeyRangeTracker(ByteKeyRange range); static ByteKeyRangeTracker of(ByteKeyRange range); @Override ByteKeyRange currentRestriction(); @Override SplitResult<ByteKeyRange> trySplit(double fractionOfRemainder); @Override boolean tryClaim(ByteKey key); @Override void checkDone(); @Override IsBounded isBounded(); @Override String toString(); @Override Progress getProgress();  }
@Test public void testTryClaim() throws Exception { ByteKeyRange range = ByteKeyRange.of(ByteKey.of(0x10), ByteKey.of(0xc0)); ByteKeyRangeTracker tracker = ByteKeyRangeTracker.of(range); assertEquals(range, tracker.currentRestriction()); assertTrue(tracker.tryClaim(ByteKey.of(0x10))); assertTrue(tracker.tryClaim(ByteKey.of(0x10, 0x00))); assertTrue(tracker.tryClaim(ByteKey.of(0x10, 0x00, 0x00))); assertTrue(tracker.tryClaim(ByteKey.of(0x50))); assertTrue(tracker.tryClaim(ByteKey.of(0x99))); assertFalse(tracker.tryClaim(ByteKey.of(0xc0))); tracker.checkDone(); }