Package de.xima.fc.common.counter
Interface Counter<T extends Comparable<T>>
-
- Type Parameters:
T- The type of value that is counted.
- All Known Subinterfaces:
Counter.LongCounter
public interface Counter<T extends Comparable<T>>A generic interface for objects that keep a count, using a value from a discrete domain.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceCounter.LongCounter
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidchangeBy(long amount)Changes the counter by the specific amount of units.default TchangeByAndGet(long amount)Changes the counter by the specific amount of units and returns the new value.Tcurrent()Get the current value of the counter.default voiddecrement()Decrements the counter by a single unit.default TdecrementAndGet()Decrements the counter by a single unit and returns the new value.com.google.common.collect.DiscreteDomain<T>domain()Gets the domain discrete domain to which the counter value belongs.default TgetAndChangeBy(long amount)Gets the current value of the counter, then changes the counter by the specific amount of units.default TgetAndDecrement()Gets the current value of the counter, then decrements the counter by a single unit.default TgetAndIncrement()Gets the current value of the counter, then increments the counter by a single unit.default voidincrement()Increments the counter by a single unit.default TincrementAndGet()Increments the counter by a single unit and returns the new value.voidset(T value)Sets the counter to a specific value.
-
-
-
Method Detail
-
changeBy
default void changeBy(long amount)
Changes the counter by the specific amount of units. A positive amount increments the counter, a negative amount decrements the counter.The default implementation of this method is to increment or decrement the counter by repeatedly incrementing or decrementing the counter by a single unit via the domain until the desired amount is reached. Implementations are encouraged to override this method with a more efficient implementation if possible.
- Parameters:
amount- The amount to change the counter by.
-
changeByAndGet
default T changeByAndGet(long amount)
Changes the counter by the specific amount of units and returns the new value.- Parameters:
amount- The amount to change the counter by.- Returns:
- The new value of the counter after it was changed.
-
current
T current()
Get the current value of the counter.- Returns:
- The current value of the counter.
-
decrement
default void decrement()
Decrements the counter by a single unit.
-
decrementAndGet
default T decrementAndGet()
Decrements the counter by a single unit and returns the new value.- Returns:
- The new value of the counter after decrementing.
-
domain
com.google.common.collect.DiscreteDomain<T> domain()
Gets the domain discrete domain to which the counter value belongs.- Returns:
- The domain of the counter value.
-
getAndChangeBy
default T getAndChangeBy(long amount)
Gets the current value of the counter, then changes the counter by the specific amount of units.- Parameters:
amount- The amount to change the counter by.- Returns:
- The previous value of the counter.
-
getAndDecrement
default T getAndDecrement()
Gets the current value of the counter, then decrements the counter by a single unit.- Returns:
- The previous value of the counter.
-
getAndIncrement
default T getAndIncrement()
Gets the current value of the counter, then increments the counter by a single unit.- Returns:
- The previous value of the counter.
-
increment
default void increment()
Increments the counter by a single unit.
-
incrementAndGet
default T incrementAndGet()
Increments the counter by a single unit and returns the new value.- Returns:
- The new value of the counter after incrementing.
-
set
void set(T value)
Sets the counter to a specific value.- Parameters:
value- The value to set the counter to.
-
-