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

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