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