ch.aplu.nxt
Class CQueue

java.lang.Object
  extended by ch.aplu.nxt.CQueue

public class CQueue
extends java.lang.Object

Implementation of a circular queue of fixed size (FIFO buffer) containing elements of class CQueueData.

See Also:
CQueueData

Constructor Summary
CQueue(int size)
          Creates a queue with given maximal number of elements.
 
Method Summary
 int available()
          Returns the current number of data elements in the queue.
 CQueueData get()
          Returns the next element from the queue.
 boolean put(CQueueData data)
          Puts given given element at the next position of the queue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CQueue

public CQueue(int size)
Creates a queue with given maximal number of elements. For size <= 0 no buffer is available.

Parameters:
size - the size of the queue (maximal number of elements before overrun)
Method Detail

put

public boolean put(CQueueData data)
Puts given given element at the next position of the queue.

Returns:
true, if successful; false, if overrun or no buffer available

get

public CQueueData get()
Returns the next element from the queue.

Returns:
a reference to a clone of the next available element or null, if queue is empty or no buffer available

available

public int available()
Returns the current number of data elements in the queue.

Returns:
the number of elements or -1 if no buffer available