class Atomics {

    public static int getAndDecrement(AtomicInteger i, int minValue) {
        return i.getAndUpdate(prev -> {
            if (prev > minValue) {
                return prev - 1;
            } else {
                return minValue;
            }
        });
    }

}