com.mischiefbox.dmud.util
Class Queue

java.lang.Object
  |
  +--com.mischiefbox.dmud.util.Queue
Direct Known Subclasses:
InputQueue

public class Queue
extends Object

Implements a basic FIFO queue. Uses a linked list to queue objects. Objects are retrieved from the head of the list, and enqueued at the end of the list. Provides synchronization to make the queue thread-safe.

Version:
$Id: Queue.java,v 1.1.1.1 2001/06/27 01:33:17 cjones Exp $
Author:
Chris Jones

Constructor Summary
Queue()
          Construct a new Queue.
 
Method Summary
 Object dequeue()
          Dequeue the next object on the queue.
 void enqueue(Object o)
          Enqueue a new object.
 int getSize()
          Get the number of elements in the queue.
 Object peek()
          Peeks at the next object available on 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()
Construct a new Queue.
Method Detail

enqueue

public void enqueue(Object o)
Enqueue a new object.
Parameters:
o - the object to be enqueued.

dequeue

public Object dequeue()
               throws NoSuchElementException
Dequeue the next object on the queue.
Returns:
the next object available.
Throws:
NoSuchElementException - if the queue is empty.

peek

public Object peek()
            throws NoSuchElementException
Peeks at the next object available on the queue. This method is not synchronized. If this queue is being accessed by more than one thread, this object may be different from the one retrieved by dequeue().
Returns:
the next object available.
Throws:
NoSuchElementException - if the queue is empty.

getSize

public int getSize()
Get the number of elements in the queue. This method is not synchronized and may return inconsistent results.
Returns:
the number of elements in the queue.


Copyright © 2001 by Christopher R. Jones. All Rights Reserved.