wyvern.util
Class Queue

java.lang.Object
  extended bywyvern.util.Queue

public class Queue
extends java.lang.Object

This class implements a standard thread-safe queue. Calling dequeue() will block the caller until something is placed in the queue by another thread.

Version:
1.0, Mar 28, 1999
Author:
Steve Yegge

Constructor Summary
Queue()
          Constructs a new Queue
 
Method Summary
 java.lang.Object dequeue()
          Removes an object from the front of the queue.
 void enqueue(java.lang.Object obj)
          Puts an object at the rear of the queue.
 java.util.List getItems()
          Returns the list of items in the queue.
 boolean isEmpty()
          Returns true if the queue contains no items.
 void pushFront(java.lang.Object obj)
          Puts an object at the front of the queue.
 boolean remove(java.lang.Object obj)
          Removes an object from the queue.
 int size()
          Returns the number of items currently in the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Constructs a new Queue

Method Detail

enqueue

public void enqueue(java.lang.Object obj)
Puts an object at the rear of the queue.

Parameters:
obj - any object to enqueue

pushFront

public void pushFront(java.lang.Object obj)
Puts an object at the front of the queue.

Parameters:
obj - the object to push-front

dequeue

public java.lang.Object dequeue()
Removes an object from the front of the queue.

Returns:
the object at the front. Blocks until an object is available.

isEmpty

public boolean isEmpty()
Returns true if the queue contains no items.

Returns:
true if the queue is empty

size

public int size()
Returns the number of items currently in the queue.

Returns:
the current queue length

getItems

public java.util.List getItems()
Returns the list of items in the queue. This is the *actual* list, not a copy of it, so make sure you synchronize on the Queue object (not the list this method returns) to prevent synchronization problems.


remove

public boolean remove(java.lang.Object obj)
Removes an object from the queue.

Parameters:
obj - the object to remove
Returns:
true if the object was in the queue