gov.nist.nlpir.irf.util
Class CircQueue

java.lang.Object
  |
  +--gov.nist.nlpir.irf.util.CircQueue

public class CircQueue
extends java.lang.Object

A circular queue of keys and associated values

Version:
$Revision: 1.1 $
Author:
This software was produced by NIST, an agency of the U.S. government, and by statute is not subject to copyright in the United States. Recipients of this software assume all responsibilities associated with its operation, modification and maintenance.

Field Summary
private  int backOne
          Value to add to index to get previous
private  java.lang.Object[] keys
          Array of keys to queue
private  int newestIndex
          Index of most recently added value
private  int qMod
          Modulus to give queue its circularity
private  java.lang.Object[] values
          Array of values, each associated with keys at same index
 
Constructor Summary
CircQueue(int maxEntries)
          Constructs a new, empty circular queue of the size specified
 
Method Summary
 void add(java.lang.Object key, java.lang.Object value)
          Adds an object (key-value pair) to the queue
 java.lang.Object find(java.lang.Object key)
          Finds the most recently added value with the given key
 void present()
          Presents the contents of the queue, most recent first
 void replace(java.lang.Object key, java.lang.Object value)
          Finds the most recently added value with the given key
 void setMaxEntries(int newMaxEntries)
          Constructs a new, empty circular queue of the size specified with as much data from the old as will fit
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

keys

private java.lang.Object[] keys
Array of keys to queue

values

private java.lang.Object[] values
Array of values, each associated with keys at same index

newestIndex

private int newestIndex
Index of most recently added value

qMod

private int qMod
Modulus to give queue its circularity

backOne

private int backOne
Value to add to index to get previous
Constructor Detail

CircQueue

public CircQueue(int maxEntries)
Constructs a new, empty circular queue of the size specified
Parameters:
maxEntries - maximum number of entries the queue can hold
Method Detail

setMaxEntries

public void setMaxEntries(int newMaxEntries)
Constructs a new, empty circular queue of the size specified with as much data from the old as will fit
Parameters:
maxEntries - maximum number of entries the queue can hold

add

public final void add(java.lang.Object key,
                      java.lang.Object value)
Adds an object (key-value pair) to the queue
Parameters:
key - of object to be added
value - of object to be added

find

public final java.lang.Object find(java.lang.Object key)
Finds the most recently added value with the given key
Parameters:
key - search key of object sought
Returns:
the most recent value with the given key or null if none found

replace

public final void replace(java.lang.Object key,
                          java.lang.Object value)
Finds the most recently added value with the given key
Parameters:
key - search key of object sought
value - replacement value

present

public void present()
Presents the contents of the queue, most recent first