ByteKeyRangeTracker extends RestrictionTracker<ByteKeyRange, ByteKey> implements HasProgress { @Override public SplitResult<ByteKeyRange> trySplit(double fractionOfRemainder) { if (NO_KEYS.equals(range) || (!range.getEndKey().isEmpty() && range.getStartKey().equals(range.getEndKey()))) { return null; } if (lastAttemptedKey != null && lastAttemptedKey.isEmpty()) { return null; } ByteKey unprocessedRangeStartKey = (lastAttemptedKey == null) ? range.getStartKey() : next(lastAttemptedKey); ByteKey endKey = range.getEndKey(); if (!endKey.isEmpty() && unprocessedRangeStartKey.compareTo(endKey) >= 0) { return null; } if (fractionOfRemainder == 0.0) { if (lastAttemptedKey == null) { ByteKeyRange rval = range; range = range.getStartKey().isEmpty() ? NO_KEYS : ByteKeyRange.of(range.getStartKey(), range.getStartKey()); return SplitResult.of(range, rval); } else { range = ByteKeyRange.of(range.getStartKey(), unprocessedRangeStartKey); return SplitResult.of(range, ByteKeyRange.of(unprocessedRangeStartKey, endKey)); } } ByteKeyRange unprocessedRange = ByteKeyRange.of(unprocessedRangeStartKey, range.getEndKey()); ByteKey splitPos; try { splitPos = unprocessedRange.interpolateKey(fractionOfRemainder); checkState(!splitPos.isEmpty()); } catch (Exception e) { return null; } if (!range.getEndKey().isEmpty() && splitPos.compareTo(range.getEndKey()) >= 0) { return null; } range = ByteKeyRange.of(range.getStartKey(), splitPos); return SplitResult.of(range, ByteKeyRange.of(splitPos, endKey)); } 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 testTrySplit() throws Exception { ByteKeyRangeTracker tracker = ByteKeyRangeTracker.of(ByteKeyRange.ALL_KEYS); SplitResult<ByteKeyRange> res = tracker.trySplit(0.5); assertKeyRangeEqualExceptPadding( ByteKeyRange.of(ByteKey.EMPTY, ByteKey.of(0x80)), res.getPrimary()); assertKeyRangeEqualExceptPadding( ByteKeyRange.of(ByteKey.of(0x80), ByteKey.EMPTY), res.getResidual()); tracker.tryClaim(ByteKey.of(0x00)); res = tracker.trySplit(0.5); assertKeyRangeEqualExceptPadding( ByteKeyRange.of(ByteKey.EMPTY, ByteKey.of(0x40)), res.getPrimary()); assertKeyRangeEqualExceptPadding( ByteKeyRange.of(ByteKey.of(0x40), ByteKey.of(0x80)), res.getResidual()); assertNull(tracker.trySplit(1)); }