com.croftsoft.core.util.queue
Class ListQueue

java.lang.Object
  extended by com.croftsoft.core.util.queue.ListQueue
All Implemented Interfaces:
Queue, Serializable

public final class ListQueue
extends Object
implements Queue, Serializable

An implementation of Queue that relies upon a List backbone.

Since:
1999-02-07
Version:
2003-06-06
See Also:
Serialized Form
Author:
David Wallace Croft

Constructor Summary
ListQueue()
           
ListQueue(List list)
           
ListQueue(List list, int maxSize)
           
 
Method Summary
 boolean append(Object o)
          Appends the object to the queue and notifies any threads that are blocked in pull().
 Object poll()
          Poll this queue to see if an object is available, immediately removing one if so.
 Object pull()
          Remove the next object in this queue, blocking until one becomes available.
 Object pull(long timeout)
          Remove the next object in this queue, blocking until one becomes available or the given timeout period expires.
 Object replace(Object o)
          Replaces the first occurrence of any equal object in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListQueue

public ListQueue(List list,
                 int maxSize)

ListQueue

public ListQueue(List list)

ListQueue

public ListQueue()
Method Detail

append

public boolean append(Object o)
Description copied from interface: Queue
Appends the object to the queue and notifies any threads that are blocked in pull().

Specified by:
append in interface Queue
Returns:
Returns true if the object could be added to the queue.

poll

public Object poll()
Description copied from interface: Queue
Poll this queue to see if an object is available, immediately removing one if so. If the queue is empty, this method immediately returns null.

Specified by:
poll in interface Queue
Returns:
An object, if one was immediately available, otherwise null.

pull

public Object pull()
            throws InterruptedException
Description copied from interface: Queue
Remove the next object in this queue, blocking until one becomes available.

Specified by:
pull in interface Queue
Throws:
InterruptedException - If the wait is interrupted.

pull

public Object pull(long timeout)
            throws InterruptedException
Description copied from interface: Queue
Remove the next object in this queue, blocking until one becomes available or the given timeout period expires.

Specified by:
pull in interface Queue
Parameters:
timeout - If positive, block for up to timeout milliseconds while waiting for an object to be added to this queue. If zero, block indefinitely.
Returns:
An object, if one was available within the specified timeout period, otherwise null.
Throws:
InterruptedException - If the timeout wait is interrupted.

replace

public Object replace(Object o)
               throws IndexOutOfBoundsException
Description copied from interface: Queue
Replaces the first occurrence of any equal object in the queue. The new object is placed in the same queue order as the old. If the new object is unique, it is simply appended.

Specified by:
replace in interface Queue
Returns:
The old object, if available, otherwise null.
Throws:
IndexOutOfBoundsException - If appending would cause the queue to exceed the maximum size.

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)