OffsetRangeTracker implements RangeTracker<Long> { public synchronized long getPositionForFractionConsumed(double fraction) { if (stopOffset == OFFSET_INFINITY) { throw new IllegalArgumentException( "getPositionForFractionConsumed is not applicable to an unbounded range: " + this); } return (long) Math.floor(startOffset + fraction * (stopOffset - startOffset)); } OffsetRangeTracker(long startOffset, long stopOffset); private  OffsetRangeTracker(); synchronized boolean isStarted(); synchronized boolean isDone(); @Override synchronized Long getStartPosition(); @Override synchronized Long getStopPosition(); @Override boolean tryReturnRecordAt(boolean isAtSplitPoint, Long recordStart); synchronized boolean tryReturnRecordAt(boolean isAtSplitPoint, long recordStart); @Override boolean trySplitAtPosition(Long splitOffset); synchronized boolean trySplitAtPosition(long splitOffset); synchronized long getPositionForFractionConsumed(double fraction); @Override synchronized double getFractionConsumed(); synchronized long getSplitPointsProcessed(); synchronized boolean markDone(); @Override synchronized String toString(); static final long OFFSET_INFINITY; }
@Test public void testGetPositionForFractionDense() throws Exception { OffsetRangeTracker tracker = new OffsetRangeTracker(3, 6); assertEquals(3, tracker.getPositionForFractionConsumed(0.0)); assertEquals(3, tracker.getPositionForFractionConsumed(1.0 / 6)); assertEquals(3, tracker.getPositionForFractionConsumed(0.333)); assertEquals(4, tracker.getPositionForFractionConsumed(0.334)); assertEquals(4, tracker.getPositionForFractionConsumed(0.666)); assertEquals(5, tracker.getPositionForFractionConsumed(0.667)); assertEquals(5, tracker.getPositionForFractionConsumed(0.999)); assertEquals(6, tracker.getPositionForFractionConsumed(1.0)); }