InputInterval implements Input { @Override public CycleSegment getInputSegment(int segmentLength) { while (true) { int current = next.intValue(); int nextCurrent = current + segmentLength; if (nextCurrent > nextMin) { return null; } if (next.compareAndSet(current,nextCurrent)) { return new Segment(current,nextCurrent); } } } InputInterval(long min, long nextMin); @Override CycleSegment getInputSegment(int segmentLength); String toString(); @Override boolean isContiguous();  }
@Test public void testBasicInterval() { InputInterval ii = new InputInterval(3,6); CycleSegment s1 = ii.getInputSegment(1); assertThat(s1).isNotNull(); assertThat(s1.isExhausted()).isFalse(); long v1 = s1.nextCycle(); assertThat(v1).isEqualTo(3); CycleSegment s2 = ii.getInputSegment(2); assertThat(s2).isNotNull(); assertThat(s2.isExhausted()).isFalse(); long v2 = s2.nextCycle(); assertThat(v2).isEqualTo(4); assertThat(s2.isExhausted()).isFalse(); long v3 = s2.nextCycle(); assertThat(v3).isEqualTo(5); assertThat(s2.isExhausted()).isTrue(); long v4 = s2.nextCycle(); assertThat(v4).isLessThan(0); assertThat(ii.getInputSegment(1)).isNull(); }