org.onemind.commons.java.datastructure
Class CounterQueue

java.lang.Object
  extended by org.onemind.commons.java.datastructure.CounterQueue

public class CounterQueue
extends java.lang.Object

Represent a list of counters with a queue per counter objectYou can queue and dequeue to a counter identified by a counter object. NOTE: This class is not thread-safe

Version:
$Id: CounterQueue.java,v 1.3 2005/04/26 17:41:24 thlee Exp $ $Name: $
Author:
TiongHiang Lee (thlee@onemindsoft.org)

Field Summary
private  java.util.HashMap _counters
          the counters *
 
Constructor Summary
CounterQueue()
          
 
Method Summary
private  java.util.List _getList(java.lang.Object o)
          Get the list for the counter object
 boolean addToQueue(java.lang.Object o, java.lang.Object queuer)
          Add an queuer to the queue of the counter object.
 java.util.List clearQueue(java.lang.Object o)
          Clear the queue of the counter object
 java.util.List getQueue(java.lang.Object o)
          Get the (unmodifiable) queue of the counter object
 boolean removeFromQueue(java.lang.Object o, java.lang.Object queuer)
          Remove the queuer from the queue of the counter object.
 java.lang.Object removeNextFromQueue(java.lang.Object counter)
          Remove the next queuer in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_counters

private java.util.HashMap _counters
the counters *

Constructor Detail

CounterQueue

public CounterQueue()

Method Detail

_getList

private java.util.List _getList(java.lang.Object o)
Get the list for the counter object

Parameters:
o - the counter object
Returns:
the list, or null if there's none

getQueue

public java.util.List getQueue(java.lang.Object o)
Get the (unmodifiable) queue of the counter object

Parameters:
o - the counter object
Returns:
the queue

clearQueue

public java.util.List clearQueue(java.lang.Object o)
Clear the queue of the counter object

Parameters:
o - the counter object
Returns:
the queue for the counter object

addToQueue

public boolean addToQueue(java.lang.Object o,
                          java.lang.Object queuer)
Add an queuer to the queue of the counter object. A queue will be created if there's none for the counter object

Parameters:
o - the counter object
queuer - the queue
Returns:
true

removeNextFromQueue

public java.lang.Object removeNextFromQueue(java.lang.Object counter)
Remove the next queuer in the queue. Null if queue is empty

Parameters:
counter - the counter
Returns:
the next queuer in the counter, or null if queue is empty

removeFromQueue

public boolean removeFromQueue(java.lang.Object o,
                               java.lang.Object queuer)
Remove the queuer from the queue of the counter object. If there's no queue for the counter object, it will do nothing and return false.

Parameters:
o - the counter object
queuer - the queuer
Returns:
true if list contains the element