public synchronized void setValue(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } super.setValue(newValue); }
public synchronized void setValue(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } super.setValue(newValue); }
public synchronized void setValue(long newValue) { if (newValue < minBound) { newValue = minBound; } else if (newValue > maxBound) { newValue = maxBound; } super.setValue(newValue); }
/** * 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); } }
/** * 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); } }
/** * 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); } }
public synchronized long increment(long amount) { long current = getValue(); if (current + amount >= maxBound) { super.setValue(maxBound); return maxBound; } return super.increment(amount); }
public synchronized long decrement(long amount) { long current = getValue(); if (current - amount <= minBound) { super.setValue(minBound); return minBound; } return super.decrement(amount); }
public synchronized long decrement(long amount) { long current = getValue(); if (current - amount <= minBound) { super.setValue(minBound); return minBound; } return super.decrement(amount); }
public synchronized long decrement(long amount) { long current = getValue(); if (current - amount <= minBound) { super.setValue(minBound); return minBound; } return super.decrement(amount); }
public synchronized long increment(long amount) { long current = getValue(); if (current + amount >= maxBound) { super.setValue(maxBound); return maxBound; } return super.increment(amount); }
public synchronized long increment(long amount) { long current = getValue(); if (current + amount >= maxBound) { super.setValue(maxBound); return maxBound; } return super.increment(amount); }