/** * Performs an atomic getAndSet(0). */ public long getAndReset() { return getAndSet(0L); }
public synchronized void setValue(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } super.setValue(newValue); }
public synchronized long increment() { long current = getValue(); if (current >= maxBound) { return current; } return super.increment(); }
public synchronized long decrement() { long current = getValue(); if (current <= minBound) { return current; } return super.decrement(); }
public synchronized long increment() { long current = getValue(); if (current >= maxBound) { return current; } return super.increment(); }
public synchronized long decrement() { long current = getValue(); if (current <= minBound) { return current; } return super.decrement(); }
/** * Performs an atomic getAndSet(0). */ public long getAndReset() { return getAndSet(0L); }
public synchronized void setValue(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } super.setValue(newValue); }
public synchronized long increment() { long current = getValue(); if (current >= maxBound) { return current; } return super.increment(); }
public synchronized long decrement() { long current = getValue(); if (current <= minBound) { return current; } return super.decrement(); }
public synchronized long getAndSet(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } return super.getAndSet(newValue); }
public synchronized void setValue(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } super.setValue(newValue); }
/** * Performs an atomic getAndSet(0). */ public long getAndReset() { return getAndSet(0L); }
/** * Creates a bounded counter with the given initial value and bounds. * * @param initialValue the initial counter value * @param minValue the inclusive upper bound * @param maxValue the inclusive lower bound */ public BoundedCounter(long initialValue, long minValue, long maxValue) { super(initialValue); this.minBound = Math.min(minValue, maxValue); this.maxBound = Math.max(minValue, maxValue); if (initialValue < minBound) { super.setValue(minBound); } else if (initialValue > maxBound) { super.setValue(maxBound); } }