org.jSyncManager.API.Tools

Class 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.

Field Summary

static int
DEFAULT_QUEUE_LENGTH
The default queue length of 4.

Constructor Summary

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.

Method Summary

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.

Field Details

DEFAULT_QUEUE_LENGTH

public static final int DEFAULT_QUEUE_LENGTH
The default queue length of 4.
Field Value:
4

Constructor Details

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.
Parameters:
size - the length to construct the queue with.

Method Details

addElement

public void addElement(Object obj)
            throws CircularQueueOverrunException
Adds an element to the queue.
Parameters:
obj - the new element to add to the queue.
Throws:
CircularQueueOverrunException - in an overrun condition occurs (ie: the queue is full).

clear

public void clear()
Clears the queue of all elements, and resets it.

getNextElement

public Object getNextElement()
            throws CircularQueueUnderrunException
Retreives the next element in the queue.
Returns:
the next element in the queue.
Throws:
CircularQueueUnderrunException - if an underrun exception occurs (ie: there is no data to return).

getQueueLength

public int getQueueLength()
Returns the capacity of the queue.
Returns:
the capacity of the queue.

incQueueEnd

protected int incQueueEnd()
            throws CircularQueueOverrunException
Increment the end pointer for the queue. If the end pointer's incrementation would cause it to overwrite the start pointer, a CircularQueueOverrunException will occur.
Returns:
the new value for the queue end pointer.
Throws:
CircularQueueOverrunException - if the input queue is overrun.

incQueueStart

protected int incQueueStart()
            throws CircularQueueUnderrunException
Increment 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.
Returns:
the new value for the queue start pointer.
Throws:
CircularQueueUnderrunException - if the queue is underrun.

isQueueEmpty

public boolean isQueueEmpty()
Tests to see if the queue is empty.
Returns:
true if the queue is empty, false otherwise.