org.oddjob.logging.cache
Class SimpleCounter

java.lang.Object
  extended by org.oddjob.logging.cache.SimpleCounter

public class SimpleCounter
extends Object

A counter which counts many things and executes an action when the count of things reaches zero or a thing is first created.

Author:
Rob Gordon.

Constructor Summary
SimpleCounter()
           
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleCounter

public SimpleCounter()
Method Detail

add

public void add(Object key)
Add an object to be counted without an action.

Parameters:
key - The object to count.

add

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

Parameters:
key - The thing to count.
newAction - The action to take if this is the first thing.

remove

public void remove(Object key)
            throws IllegalStateException
Remove an object taking no action if the count of that object reaches 0.

Parameters:
key - The object to remove from the count.
Throws:
IllegalStateException - If the object was never counted.

remove

public void remove(Object key,
                   Runnable emptyAction)
            throws IllegalStateException
Remove an object from the count. If the count is zero after removal execute the given action.

Parameters:
key - The object that will decrement the count.
emptyAction - Action to take when the count is 0.
Throws:
IllegalStateException - If the object was never counted.