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
public class ObjectCounting<T> extends Object
A class for counting objects thread-safe. This resembles anAtomicLong
but object-specific.- Author:
- Ulrich Kreher
-
-
Constructor Summary
Constructors Constructor Description ObjectCounting()
Creates 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description long
decreaseAndGetCount(T object)
Decreases and gets the count for the designated object.long
getCount(T object)
Returns the current count for the designated object.long
increaseAndGetCount(T object)
Increases and gets the count for the designated object.boolean
isEmpty()
Gets whether this object counting has at least one count for an arbitrary object.
-
-
-
Constructor Detail
-
ObjectCounting
public ObjectCounting()
Creates a new instance for object counting using a logger for this class (ObjectCounting, not a subclass).
-
ObjectCounting
public ObjectCounting(Logger logger)
Creates a new instance for object counting using the designated logger.- Parameters:
logger
- The logger for information on object counting.
-
-
Method Detail
-
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
public long getCount(T object)
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
public long increaseAndGetCount(T object)
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
public long decreaseAndGetCount(T object)
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.
-
-