org.jSyncManager.API.Tools
Class CircularQueue
java.lang.Objectorg.jSyncManager.API.Tools.CircularQueue
public class CircularQueue
extends java.lang.Object
The Circular Queue class.
This class defines a circular queue. A circular queue is an
array-based queue, where the entry-order wraps around the end
of the queue, back to the beginning, as elements are added and removed.
CircularQueue()- Constructs a new Circular Queue object with the default queue size.
|
CircularQueue(int size)- Constructs a new Circular Queue object with the specified queue size.
|
void | addElement(Object obj)- Adds an element to the queue.
|
void | clear()- Clears the queue of all elements, and resets it.
|
Object | getNextElement()- Retreives the next element in the queue.
|
int | getQueueLength()- Returns the capacity of the queue.
|
protected int | incQueueEnd()- Increment the end pointer for the queue.
|
protected int | incQueueStart()- Increment the start pointer for the queue.
|
boolean | isQueueEmpty()- Tests to see if the queue is empty.
|
DEFAULT_QUEUE_LENGTH
public static final int DEFAULT_QUEUE_LENGTH
The default queue length of 4.
CircularQueue
public CircularQueue()
Constructs a new Circular Queue object with the default queue size.
CircularQueue
public CircularQueue(int size)
Constructs a new Circular Queue object with the specified queue size.
size - the length to construct the queue with.
addElement
public void addElement(Object obj)
throws CircularQueueOverrunExceptionAdds an element to the queue.
obj - the new element to add to the queue.
clear
public void clear()
Clears the queue of all elements, and resets it.
getNextElement
public Object getNextElement()
throws CircularQueueUnderrunExceptionRetreives the next element in the queue.
- the next element in the queue.
getQueueLength
public int getQueueLength()
Returns the capacity of the queue.
- the capacity of the queue.
incQueueEnd
protected int incQueueEnd()
throws CircularQueueOverrunExceptionIncrement the end pointer for the queue.
If the end pointer's incrementation would cause it to overwrite the
start pointer, a CircularQueueOverrunException will occur.
- the new value for the queue end pointer.
incQueueStart
protected int incQueueStart()
throws CircularQueueUnderrunExceptionIncrement the start pointer for the queue.
If the start pointer's incrementation would cause it to pass the cell referenced by
to by the end pointer (ie: an underrun occurs), a CircularQueueUnderrunException will occur.
- the new value for the queue start pointer.
isQueueEmpty
public boolean isQueueEmpty()
Tests to see if the queue is empty.
- true if the queue is empty, false otherwise.