wyvern.common.util
Class VectorQueue

java.lang.Object
  extended bywyvern.common.util.VectorQueue

public class VectorQueue
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. It's 1.1-compatible, but the dequeue() operation is O(n), since Vector.removeElementAt(0) has to shuffle all the remaining elements to the left.

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

Constructor Summary
VectorQueue()
          Constructs a new VectorQueue
 
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.Vector getItems()
          Returns the list of items in the queue.
 boolean isEmpty()
          Returns true if the queue contains no items.
 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

VectorQueue

public VectorQueue()
Constructs a new VectorQueue

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

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