net.sf.zig_project.gpl.common.queue
Class PriorityQueueBase

java.lang.Object
  extended bynet.sf.zig_project.gpl.common.queue.PriorityQueueBase
All Implemented Interfaces:
OrderedBlockingQueue, Queue
Direct Known Subclasses:
GenericPriorityQueue

public abstract class PriorityQueueBase
extends Object
implements OrderedBlockingQueue

Base implementation for a Priority Queue. A priority queue consists of elements being associated with a priority as they are queued. Hence, higher priority elements will be dequeued before lower priority elements, regardless of the order in which they were queued. Since this implementation of priority queue consists of a set of queues, elements with the same priority will be ordered by the queue associated with that specific priority. The lowest priority in a priority queue is always 0.

Version:
April 20, 2005
Author:
Frank Ziglar

Nested Class Summary
protected  class PriorityQueueBase.QueueSequencer
          Provides an Enumeration of the internal queues within the priority queue.
 
Field Summary
protected  OrderedQueue[] queues
           
 
Constructor Summary
PriorityQueueBase(OrderedQueue[] qs)
          Creates a Priority Queue out of the array of OrderedQueues.
 
Method Summary
 void clear()
          Empties the Queue.
 boolean contains(Object o)
          Determines if the Queue contains a copy of the specified Object.
 Enumeration elements()
          Retrieves a list of the elements currently in the queue in a form suitable to enumerate over.
 int getMaxPriority()
          Determines the maximum priority at which an element can be queued for this queue.
 boolean isEmpty()
          Determines if the Queue is empty.
 Object peekNext()
          Retrieves the next Object from the queue without removing it.
 Object remove(Object o)
          Removes the first found element that is equal to o from the queue.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.sf.zig_project.gpl.common.queue.OrderedBlockingQueue
removeNext
 

Field Detail

queues

protected final OrderedQueue[] queues
Constructor Detail

PriorityQueueBase

public PriorityQueueBase(OrderedQueue[] qs)
Creates a Priority Queue out of the array of OrderedQueues. The same array is used (it is anticipated that calls to this constructor should throw away the reference to the array after constructing the queue).

Method Detail

clear

public void clear()
Description copied from interface: Queue
Empties the Queue. All elements are cleared out, and the Queue will be empty after this call.

Specified by:
clear in interface Queue

contains

public boolean contains(Object o)
Description copied from interface: Queue
Determines if the Queue contains a copy of the specified Object.

Specified by:
contains in interface Queue
Parameters:
o - an Object to look for copies of
Returns:
true if at least one copy of o was found in the queue

isEmpty

public boolean isEmpty()
Description copied from interface: Queue
Determines if the Queue is empty. An empty queue contains no elements.

Specified by:
isEmpty in interface Queue
Returns:
true only if the Queue is empty

remove

public Object remove(Object o)
Description copied from interface: Queue
Removes the first found element that is equal to o from the queue.

Specified by:
remove in interface Queue
Parameters:
o - a copy of the Object to be removed
Returns:
the first copy of o found, or null if no copy was found.

peekNext

public Object peekNext()
Description copied from interface: OrderedBlockingQueue
Retrieves the next Object from the queue without removing it. This method will always return immediately.

Specified by:
peekNext in interface OrderedBlockingQueue
Returns:
the next Object in the queue, or null if the queue was empty

getMaxPriority

public int getMaxPriority()
Determines the maximum priority at which an element can be queued for this queue. The minimum is always 0.

Returns:
the maximum priority this queue supports

elements

public Enumeration elements()
Description copied from interface: Queue
Retrieves a list of the elements currently in the queue in a form suitable to enumerate over. Operations on the Enumeration after this queue has been modified are not anticipated, and may cause unforseen problems.

Specified by:
elements in interface Queue
Returns:
an Enumeration of the elements in the queue