@Test void testGetAndDecrement() { int init = 10; int min = 5; AtomicInteger integer = new AtomicInteger(init); for (int i = init; i > 0; i--) { Atomics.getAndDecrement(integer, min); } assertEquals(min, integer.get()); }
public static int getAndDecrement(AtomicInteger i, int minValue) { return i.getAndUpdate(prev -> { if (prev > minValue) { return prev - 1; } else { return minValue; } }); }
Atomics { public static int getAndDecrement(AtomicInteger i, int minValue) { return i.getAndUpdate(prev -> { if (prev > minValue) { return prev - 1; } else { return minValue; } }); } }
Atomics { public static int getAndDecrement(AtomicInteger i, int minValue) { return i.getAndUpdate(prev -> { if (prev > minValue) { return prev - 1; } else { return minValue; } }); }  }
Atomics { public static int getAndDecrement(AtomicInteger i, int minValue) { return i.getAndUpdate(prev -> { if (prev > minValue) { return prev - 1; } else { return minValue; } }); }  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); }
Atomics { public static int getAndDecrement(AtomicInteger i, int minValue) { return i.getAndUpdate(prev -> { if (prev > minValue) { return prev - 1; } else { return minValue; } }); }  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);  }