Package de.aristaflow.adept2.util
Class ObjectCounting<T>
java.lang.Object
de.aristaflow.adept2.util.ObjectCounting<T>
- Type Parameters:
T- The type of the objects to count.
- Direct Known Subclasses:
ObjectEqualityLockCount
A class for counting objects thread-safe. This resembles an
AtomicLong but object-specific.- Author:
- Ulrich Kreher
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance for object counting using a logger for this class (ObjectCounting, not a subclass).ObjectCounting(Logger logger) Creates a new instance for object counting using the designated logger. -
Method Summary
Modifier and TypeMethodDescriptionlongdecreaseAndGetCount(T object) Decreases and gets the count for the designated object.longReturns the current count for the designated object.longincreaseAndGetCount(T object) Increases and gets the count for the designated object.booleanisEmpty()Gets whether this object counting has at least one count for an arbitrary object.
-
Field Details
-
objectCount
The map managing the objects and their counts. -
logger
The logger for information on object counting.
-
-
Constructor Details
-
ObjectCounting
public ObjectCounting()Creates a new instance for object counting using a logger for this class (ObjectCounting, not a subclass). -
ObjectCounting
Creates a new instance for object counting using the designated logger.- Parameters:
logger- The logger for information on object counting.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Gets whether this object counting has at least one count for an arbitrary object.- Returns:
- Whether this object counting has at least one count for an arbitrary object.
-
getCount
Returns the current count for the designated object.- Parameters:
object- The object for which to get the count.- Returns:
- The count for the designated object or 0 in case the object has no count.
-
increaseAndGetCount
Increases and gets the count for the designated object.- Parameters:
object- The object for which to increase and get the count.- Returns:
- The increased count for the designated object. This is at least 1.
-
decreaseAndGetCount
Decreases and gets the count for the designated object.- Parameters:
object- The object for which to decrease and get the count.- Returns:
- The decreased count for the designated object.
-