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 an AtomicLong but object-specific.
Author:
Ulrich Kreher
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final Logger
    The logger for information on object counting.
    protected final Map<T,Long>
    The map managing the objects and their counts.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance for object counting using a logger for this class (ObjectCounting, not a subclass).
    Creates a new instance for object counting using the designated logger.
  • Method Summary

    Modifier and Type
    Method
    Description
    long
    Decreases and gets the count for the designated object.
    long
    getCount(T object)
    Returns the current count for the designated object.
    long
    Increases and gets the count for the designated object.
    boolean
    Gets whether this object counting has at least one count for an arbitrary object.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • objectCount

      protected final Map<T,Long> objectCount
      The map managing the objects and their counts.
    • logger

      protected final Logger 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

      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 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

      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.