Source:
default List<IntervalList> scatter(final IntervalList inputList, final int scatterCount) { if (scatterCount < 1) throw new IllegalArgumentException("scatterCount < 1"); final IntervalList processedIntervalList = preprocessIntervalList(inputList); final long idealSplitWeight = deduceIdealSplitWeight(processedIntervalList, scatterCount); Log.getInstance(IntervalListScatterer.class).info("idealSplitWeight=" + idealSplitWeight); final List<IntervalList> accumulatedIntervalLists = new ArrayList<>(); IntervalList runningIntervalList = new IntervalList(processedIntervalList.getHeader()); final ArrayDeque<Interval> intervalQueue = new ArrayDeque<>(processedIntervalList.getIntervals()); long weightRemaining = listWeight(processedIntervalList); while (!intervalQueue.isEmpty() && accumulatedIntervalLists.size() < scatterCount - 1) { final Interval interval = intervalQueue.pollFirst(); final long currentSize = listWeight(runningIntervalList); final double projectedSizeOfRemainingDivisions = (weightRemaining - listWeight(runningIntervalList)) / ((double) scatterCount - accumulatedIntervalLists.size() - 1); final List<Interval> split = takeSome(interval, idealSplitWeight, currentSize, projectedSizeOfRemainingDivisions); if (split.size() != 2) { throw new IllegalStateException("takeSome should always return exactly 2 (possibly null) intervals."); } if (split.get(1) != null) { intervalQueue.addFirst(split.get(1)); } if (split.get(0) == null) { weightRemaining -= listWeight(runningIntervalList); accumulatedIntervalLists.add(runningIntervalList); runningIntervalList = new IntervalList(processedIntervalList.getHeader()); } else { runningIntervalList.add(split.get(0)); } } runningIntervalList.addall(intervalQueue); if (!runningIntervalList.getIntervals().isEmpty()) { accumulatedIntervalLists.add(runningIntervalList); } return accumulatedIntervalLists; }

Target:
default List<IntervalList> scatter(final IntervalList inputList, final int scatterCount) { if (scatterCount < 1) { throw new IllegalArgumentException("scatterCount < 1"); } final IntervalList processedIntervalList = preprocessIntervalList(inputList); final long idealSplitWeight = deduceIdealSplitWeight(processedIntervalList, scatterCount); Log.getInstance(IntervalListScatterer.class).info("idealSplitWeight=" + idealSplitWeight); final List<IntervalList> accumulatedIntervalLists = new ArrayList<>(); IntervalList runningIntervalList = new IntervalList(processedIntervalList.getHeader()); final ArrayDeque<Interval> intervalQueue = new ArrayDeque<>(processedIntervalList.getIntervals()); long weightRemaining = listWeight(processedIntervalList); while (!intervalQueue.isEmpty() && accumulatedIntervalLists.size() < scatterCount - 1) { final Interval interval = intervalQueue.pollFirst(); final long currentSize = listWeight(runningIntervalList); final double projectedSizeOfRemainingDivisions = (weightRemaining - listWeight(runningIntervalList)) / ((double) scatterCount - accumulatedIntervalLists.size() - 1); final List<Interval> split = takeSome(interval, idealSplitWeight, currentSize, projectedSizeOfRemainingDivisions); if (split.size() != 2) { throw new IllegalStateException("takeSome should always return exactly 2 (possibly null) intervals."); } if (split.get(1) != null) { intervalQueue.addFirst(split.get(1)); } if (split.get(0) == null) { weightRemaining -= listWeight(runningIntervalList); accumulatedIntervalLists.add(runningIntervalList); runningIntervalList = new IntervalList(processedIntervalList.getHeader()); } else { runningIntervalList.add(split.get(0)); } } runningIntervalList.addall(intervalQueue); if (!runningIntervalList.getIntervals().isEmpty()) { accumulatedIntervalLists.add(runningIntervalList); } return accumulatedIntervalLists; }