@Test public void test_cycle() { IntCyclicRangeCounter counter = new IntCyclicRangeCounter(4, 6); assertEquals(4, counter.getAndIncrement()); assertEquals(5, counter.getAndIncrement()); assertEquals(6, counter.getAndIncrement()); assertEquals(4, counter.getAndIncrement()); }
int getAndIncrement() { for (; ; ) { int current = counter.get(); int next = current == max ? min : current + 1; if (counter.compareAndSet(current, next)) { return current; } } }
IntCyclicRangeCounter { int getAndIncrement() { for (; ; ) { int current = counter.get(); int next = current == max ? min : current + 1; if (counter.compareAndSet(current, next)) { return current; } } } }
IntCyclicRangeCounter { int getAndIncrement() { for (; ; ) { int current = counter.get(); int next = current == max ? min : current + 1; if (counter.compareAndSet(current, next)) { return current; } } } IntCyclicRangeCounter(int min, int max); }
IntCyclicRangeCounter { int getAndIncrement() { for (; ; ) { int current = counter.get(); int next = current == max ? min : current + 1; if (counter.compareAndSet(current, next)) { return current; } } } IntCyclicRangeCounter(int min, int max);  }
IntCyclicRangeCounter { int getAndIncrement() { for (; ; ) { int current = counter.get(); int next = current == max ? min : current + 1; if (counter.compareAndSet(current, next)) { return current; } } } IntCyclicRangeCounter(int min, int max);   }