Atomics { public static int getAndIncrement(AtomicInteger i, int maxValue) { return i.getAndUpdate(prev -> { if (prev < maxValue) { return prev + 1; } else { return maxValue; } }); }  static int getAndDecrement(AtomicInteger i, int minValue); static int getAndIncrement(AtomicInteger i, int maxValue); static boolean updateMin(AtomicInteger currentMin, int newValue); static boolean updateMax(AtomicInteger currentMax, int newValue);  }
@Test void testGetAndIncrement() { int max = 10; AtomicInteger integer = new AtomicInteger(0); for (int i = 0; i < 20; i++) { Atomics.getAndIncrement(integer, max); } assertEquals(max, integer.get()); }