SK.gnome.dwarf.utils.queue
Class FIFOQueue

java.lang.Object
  extended bySK.gnome.dwarf.utils.queue.FIFOQueue
All Implemented Interfaces:
Queue

public class FIFOQueue
extends java.lang.Object
implements Queue

Provides non-blocking FIFO queue.

Maximum limit can be set for the total number of the queued elements. The queue elements are returned by the get() method in the First-In-First-Out order. The method returns quickly without blocking the caller.

Thread-safety note:
The queue implementation is not thread-safe; it must be synchronized externally to allow simultaneous access by multiple threads.


Constructor Summary
FIFOQueue()
          Creates an empty FIFOQueue with no size limit.
FIFOQueue(int size)
          Creates an empty FIFOQueue with the given maximum size limit.
 
Method Summary
 boolean add(java.lang.Object object)
          Adds the object to the queue.
 void clear()
          Removes all objects from the queue.
 java.lang.Object get()
          Returns an object from the queue.
 java.lang.Object peek()
          Returns an object from the queue.
 int size()
          Returns the queue size.
 java.lang.String toString()
          Returns the queue statistics.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FIFOQueue

public FIFOQueue()
Creates an empty FIFOQueue with no size limit.

The queue capacity will grow as needed.


FIFOQueue

public FIFOQueue(int size)
Creates an empty FIFOQueue with the given maximum size limit.

The size argument must be greater than zero. The queue will have a fixed capacity given by the argument.

Parameters:
size - the maximum queue size
Throws:
java.lang.IllegalArgumentException - if the size argument is zero or negative
Method Detail

add

public boolean add(java.lang.Object object)
Description copied from interface: Queue
Adds the object to the queue.

The method returns false if the given object could not be added to the queue. A common reason may be that the queue have a fixed capacity and the current number of the queued objects has reached the size limit.

Specified by:
add in interface Queue
Parameters:
object - the object to be added to the queue
Returns:
true if the object has been added to the queue successfully, false otherwise

get

public java.lang.Object get()
Description copied from interface: Queue
Returns an object from the queue.

The returned object is removed from the queue.

Specified by:
get in interface Queue
Returns:
the object or null if there is no object in the queue

peek

public java.lang.Object peek()
Description copied from interface: Queue
Returns an object from the queue.

The returned object remains in the queue.

Specified by:
peek in interface Queue
Returns:
the object or null if there is no object in the queue

clear

public void clear()
Description copied from interface: Queue
Removes all objects from the queue.

Specified by:
clear in interface Queue

size

public int size()
Description copied from interface: Queue
Returns the queue size.

Returns the current number of the objects in the queue.

Specified by:
size in interface Queue
Returns:
the queue size

toString

public java.lang.String toString()
Returns the queue statistics.

Returns the current/peak/total number of the queue elements.



Copyright (c) 1999-2005, Gnome Ltd. All rights reserved.