de.jaetzold.util
Class Queue

java.lang.Object
  |
  +--de.jaetzold.util.Queue
All Implemented Interfaces:
Enumeration

public class Queue
extends Object
implements Enumeration

A class for passing Objects from one Thread to another. The Threads have to take care for themselves that the Objects passed are from the correct type. Usually there is only one thread on the reading end, which retrieves the posted Objects by calling getNext(). However there can be more than one Thread calling getNext() but then, each object will always be returned only to one of them.


Constructor Summary
Queue()
           
 
Method Summary
 boolean contains(Object object)
           
 Object getNext()
          Returns and deletes the next object in the queue.
 Object getNext(int timeout)
          Returns and deletes the next event in the queue if there is any before the specified timeout.
 Object getNextEqual(Object object)
           
 Object getNextEqual(Object object, int timeout)
           
 boolean hasMoreElements()
           
 boolean isEmpty()
          Tells whether there are any objects in the queue.
 Object nextElement()
           
 Object peekNext()
          Return but not delete.
 Object peekNext(int timeout)
          Return but not delete.
 void post(Object object)
          Adds the given object to the end of the queue.
 boolean remove(Object object)
          Removes the first occurence of an element equal to the given object from this queue if there is any.
 int removeAll(Object object)
          Removes the all elements equal to the given object from this queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Queue

public Queue()
Method Detail

isEmpty

public boolean isEmpty()
Tells whether there are any objects in the queue. This only ensures that the next call to getNext() does not block if both calls are in the same block, synchronized to this queue.
See Also:
getNext()

hasMoreElements

public boolean hasMoreElements()
Specified by:
hasMoreElements in interface Enumeration

nextElement

public Object nextElement()
Specified by:
nextElement in interface Enumeration

peekNext

public Object peekNext()
                throws InterruptedException
Return but not delete.

peekNext

public Object peekNext(int timeout)
                throws InterruptedException
Return but not delete.

getNext

public Object getNext()
               throws InterruptedException
Returns and deletes the next object in the queue. If the queue is already empty, this method blocks until a new event gets added with post(java.lang.Object).
See Also:
post(java.lang.Object), getNext(int)

getNext

public Object getNext(int timeout)
               throws InterruptedException
Returns and deletes the next event in the queue if there is any before the specified timeout. If the queue is empty, this method blocks until a new event gets added with post(de.jaetzold.util.Event) or until after timeout milliseconds have elapsed. In this case it is possible that this method returns null.
Returns:
the next Event in the Queue if there is any before the timeout, null otherwise.
See Also:
post(Object), getNext()

post

public void post(Object object)
Adds the given object to the end of the queue. This method notifies all Threads currently waiting on this queues monitor.

remove

public boolean remove(Object object)
Removes the first occurence of an element equal to the given object from this queue if there is any. It calls object.equals() to determine equality. Implementation note: It relies on the underlying List to do it that way.
Returns:
false if there didn't exit such an element in this Queue, true otherwise

removeAll

public int removeAll(Object object)
Removes the all elements equal to the given object from this queue. All occurrences of such elements are removed by this method. It calls object.equals() to determine equality. Implementation note: It relies on the underlying List to do it that way.
Returns:
the number of removed occurrences (0 if there weren't any)

contains

public boolean contains(Object object)

getNextEqual

public Object getNextEqual(Object object)
                    throws InterruptedException

getNextEqual

public Object getNextEqual(Object object,
                           int timeout)
                    throws InterruptedException