net.i2p.util

## Class ObjectCounter<K>

- java.lang.Object
- - net.i2p.util.ObjectCounter<K>

- Type Parameters:
    `K` - type of objects being counted
  All Implemented Interfaces:
    Serializable

      public class ObjectCounter<K>
      extends Object
      implements Serializable

  Thread-safe counter for tracking occurrences of objects.

  This class provides a concurrent way to count how many times specific objects appear. It uses ConcurrentHashMap and AtomicInteger to ensure thread-safe operations in multi-threaded environments.

  Typical use cases include:

  - Counting message frequencies
  - Tracking request rates by client
  - Monitoring event occurrences
  - Statistical data collection
  See Also:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ObjectCounter()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `clear()` Start over.
    `void` | `clear(K h)` Reset the count for this key to zero
    `int` | `count(K h)`
    `int` | `increment(K h)` Add one.
    `void` | `max(K h)` Set a high value
    `Set<K>` | `objects()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ObjectCounter

          public ObjectCounter()

  - ### Method Detail

    - #### clear

          public void clear()

      Start over. Reset the count for all keys to zero.

    - #### clear

          public void clear(K h)

      Reset the count for this key to zero

    - #### count

          public int count(K h)

      Returns:
        current count

    - #### increment

          public int increment(K h)

      Add one.
      Returns:
        count after increment

    - #### max

          public void max(K h)

      Set a high value

    - #### objects

          public Set<K> objects()

      Returns:
        set of objects with counts > 0