K - type of objects being countedpublic class ObjectCounter<K> extends Object implements Serializable
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:
| Constructor and Description |
|---|
ObjectCounter()ObjectCounter. |
| 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) |
void | decay(int factor)Decay all counts by the given factor (integer division). |
int | increment(K h)Add one. |
void | max(K h)Set a high value |
Set<K> | objects() |
public void clear()
public void clear(K h)
public int count(K h)
public void decay(int factor)
factor - divisor for decay (e.g., 2 for 50% decay)public int increment(K h)
public void max(K h)