Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

javatools.util
Class JQueue  view JQueue download JQueue.java

java.lang.Object
  extended byjavatools.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.

Version:
0.7

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.
 
Field Summary
private  long get
          The next "get" position
private  java.util.Dictionary hash
          We store the queue here
private  long put
          The next "put" position.
 
Constructor Summary
JQueue()
          Creates a new empty JQueue.
JQueue(int size)
          Constructor which takes an initial guesstimate of how many items we expect to store in it
 
Method Summary
 void clear()
           
 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.
private  void init(int size)
          Setup initialization
 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()
          Returns 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
 

Field Detail

hash

private java.util.Dictionary hash
We store the queue here


put

private long put
The next "put" position.


get

private long get
The next "get" position

Constructor Detail

JQueue

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


JQueue

public JQueue()
Creates a new empty JQueue.

Method Detail

get

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


size

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


remove

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


clear

public void clear()

put

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


empty

public boolean empty()
Is the queue empty?


peek

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


init

private void init(int size)
Setup initialization