public class SimpleCounter
extends java.lang.Object
Constructor and Description |
---|
SimpleCounter() |
Modifier and Type | Method and Description |
---|---|
void |
add(java.lang.Object key)
Add an object to be counted without an action.
|
void |
add(java.lang.Object key,
java.lang.Runnable newAction)
Add a thing to be counted, and the action to execute if this
is the first thing to be counted.
|
void |
remove(java.lang.Object key)
Remove an object taking no action if the count of that object
reaches 0.
|
void |
remove(java.lang.Object key,
java.lang.Runnable emptyAction)
Remove an object from the count.
|
public void add(java.lang.Object key)
key
- The object to count.public void add(java.lang.Object key, java.lang.Runnable newAction)
key
- The thing to count.newAction
- The action to take if this is the first thing.public void remove(java.lang.Object key) throws java.lang.IllegalStateException
key
- The object to remove from the count.java.lang.IllegalStateException
- If the object was never counted.public void remove(java.lang.Object key, java.lang.Runnable emptyAction) throws java.lang.IllegalStateException
key
- The object that will decrement the count.emptyAction
- Action to take when the count is 0.java.lang.IllegalStateException
- If the object was never counted.