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 ClassesModifier and TypeInterfaceDescriptionstatic interface -
Method Summary
Modifier and TypeMethodDescriptiondefault 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.current()Get the current value of the counter.default voidDecrements the counter by a single unit.default TDecrements 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 TGets the current value of the counter, then decrements the counter by a single unit.default TGets the current value of the counter, then increments the counter by a single unit.default voidIncrements the counter by a single unit.default TIncrements the counter by a single unit and returns the new value.voidSets the counter to a specific value.
-
Method Details
-
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
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
-
decrement
default void decrement()Decrements the counter by a single unit. -
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
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
Gets the current value of the counter, then decrements the counter by a single unit.- Returns:
- The previous value of the counter.
-
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
Increments the counter by a single unit and returns the new value.- Returns:
- The new value of the counter after incrementing.
-
set
Sets the counter to a specific value.- Parameters:
value- The value to set the counter to.
-