javatools.util
Class JQueue

java.lang.Object
  |
  +--javatools.util.JQueue

public class JQueue
extends java.lang.Object

Implements a regular queue. The only unusual thing is you can delete things from the middle of the queue efficiently by supplying the QueueKey which is returned by put(). In terms of implementation we use a Dictionary Hashtable instead of a perhaps more traditional vector with round-robin pointers. The benefit here is efficient implementation of the remove functionality. It also happens to be a really easy way to implement queues in general. The way it works is that the dictionary is used as a sparse array. The upper and lower bounds of the sparse array keeping growing up and up towards infinity. This is ok because the key is a long and will take several million years of running before any problems arise.


Nested Class Summary
 class JQueue.QueueKey
          A class which can be used to pass to remove to remove something from the middle of the queue.
 
Constructor Summary
JQueue()
           
JQueue(int size)
          Constructor which takes an initial guesstimate of how many items we expect to store in it
 
Method Summary
 boolean empty()
          Is the queue empty?
 java.lang.Object get()
          Pull something out of the end of the queue and remove it from the queue.
 java.lang.Object peek()
          Get something out of the queue without removing it.
 JQueue.QueueKey put(java.lang.Object o)
          Push something onto the queue
 java.lang.Object remove(JQueue.QueueKey key)
          Remove an item from anywhere in the queue.
 int size()
          The number of elements in the queue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JQueue

public JQueue(int size)
Constructor which takes an initial guesstimate of how many items we expect to store in it

Parameters:
size - Description of Parameter

JQueue

public JQueue()
Method Detail

get

public java.lang.Object get()
Pull something out of the end of the queue and remove it from the queue.

Returns:
Description of the Returned Value

size

public int size()
The number of elements in the queue

Returns:
Description of the Returned Value

remove

public java.lang.Object remove(JQueue.QueueKey key)
Remove an item from anywhere in the queue.

Parameters:
key - Description of Parameter
Returns:
The object that was removed.
See Also:
Queue#put(Object)

put

public JQueue.QueueKey put(java.lang.Object o)
Push something onto the queue

Parameters:
o - Description of Parameter
Returns:
An external key that can be passed to remove() to pull it from the queue. The value of the key should be regarded as meaningless to external parties.
See Also:
Queue#remove(QueueKey)

empty

public boolean empty()
Is the queue empty?

Returns:
Description of the Returned Value

peek

public java.lang.Object peek()
Get something out of the queue without removing it.

Returns:
Description of the Returned Value