JavaTron
Class PriorityQueue

java.lang.Object
  |
  +--JavaTron.PriorityQueue

public class PriorityQueue
extends java.lang.Object

This class implements a 'PriorityQueue'. This is not a priority queue in the classic sense as usually implemented by a heap. It is rather a simple structure that allows an external user to add an item to a one queue in a list of prioritized queues.

There are n prioritized queue's, initialized at creation. The PriorityQueue will remove all items from its internal prioritized queue number 0 before removing items from number 1, and then from number 2 and so on.

There are no means for changing the priority of items in the queue, so items placed in queues higher than 0 could be starved.


Constructor Summary
PriorityQueue(int number)
          Construct a PriorityQueue with number internal prioritized queues.
 
Method Summary
 void add(java.lang.Object item, int priority)
          Add an item to the queue using the specified priority.
 boolean isEmpty()
          Returns true if all prioritized queues are empty.
 java.lang.Object remove()
          Removes the next item from the prioritized queues in order of the queues.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PriorityQueue

public PriorityQueue(int number)
Construct a PriorityQueue with number internal prioritized queues.

Parameters:
number - the number of internal queues to hold
Method Detail

add

public void add(java.lang.Object item,
                int priority)
Add an item to the queue using the specified priority.

Parameters:
item - the item to add
priority - the prioritized queue to add the item to where 0 <= priority < number where number is the initial number of prioritized queues that were created in the constructor.
Throws:
ArrayOutOfBoundsException - if !(0 <= priority < number)

isEmpty

public boolean isEmpty()
Returns true if all prioritized queues are empty.

Returns:
true if the queue is empty, false if not.

remove

public java.lang.Object remove()
Removes the next item from the prioritized queues in order of the queues. All items are removed from 0, then 1, then 2 and so on.

Returns:
remove the object removed, null if the queue is empty.