edu.uci.ics.pattis.ics22
Class SimplePriorityQueue

java.lang.Object
  extended by edu.uci.ics.pattis.ics22.SimplePriorityQueue

public class SimplePriorityQueue
extends java.lang.Object

Objects constructed from the SimplePriorityQueue class act as collections of any references to objects. We can enqueue reference to objects into this collection and dequeue references to objects from the collection (according to the highest-priority-out ordering). Note that NO METHODS are called on these objects inside this class: we just move references around.


Constructor Summary
SimplePriorityQueue(java.util.Comparator prioritizer)
          Constructs a SimplePriorityQueue object, specifying the initial size for it as 1.
SimplePriorityQueue(java.util.Comparator prioritizer, int initialSize)
          Constructs a SimplePriorityQueue object, specifying the initial size for it (number of references it can store).
 
Method Summary
 java.lang.Object dequeue()
          Returns the highest priority reference in this SimplePriorityQueue, removing it in the process.
 void enqueue(java.lang.Object o)
          Enqueue a reference into this SimplePriorityQueue.
 int getSize()
          Returns the number of reference this SimplePriorityQueue stores (0 if empty).
 boolean isEmpty()
          Returns whether or not this SimplePriorityQueue is empty (stores no references).
 void makeEmpty()
          Make this SimplePriorityQueue empty.
 java.lang.Object peek()
          Returns the highest priority reference in this SimplePriorityQueue, without removing it in the process.
 java.lang.String toString()
          Returns a String representation of the state of this SimplePriorityQueue.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimplePriorityQueue

public SimplePriorityQueue(java.util.Comparator prioritizer,
                           int initialSize)
                    throws java.lang.IllegalArgumentException
Constructs a SimplePriorityQueue object, specifying the initial size for it (number of references it can store). Initially, the SimplePriorityQueue is empty.

Parameters:
prioritizer - specifies a Comparator to use when establishing the relative priorities of the values
initialSize - specifies the number of references that the SimplePriorityQueue can initially store "
Throws:
java.lang.IllegalArgumentException - if initialSize is < 1

SimplePriorityQueue

public SimplePriorityQueue(java.util.Comparator prioritizer)
Constructs a SimplePriorityQueue object, specifying the initial size for it as 1.

Parameters:
prioritizer - specifies a Comparator to use when establishing the relative priorities of the values
Method Detail

makeEmpty

public void makeEmpty()
Make this SimplePriorityQueue empty.


enqueue

public void enqueue(java.lang.Object o)
Enqueue a reference into this SimplePriorityQueue.

Parameters:
o - specifies the reference to enqueue

dequeue

public java.lang.Object dequeue()
                         throws java.lang.IllegalStateException
Returns the highest priority reference in this SimplePriorityQueue, removing it in the process.

Returns:
the highest priority reference on this SimplePriorityQueue, removing it in the process
Throws:
java.lang.IllegalStateException - if this SimplePriorityQueue is empty

peek

public java.lang.Object peek()
                      throws java.lang.IllegalStateException
Returns the highest priority reference in this SimplePriorityQueue, without removing it in the process.

Returns:
highest priority reference in this SimplePriorityQueue, without removing it in the process
Throws:
java.lang.IllegalStateException - if this SimplePriorityQueue is empty

isEmpty

public boolean isEmpty()
Returns whether or not this SimplePriorityQueue is empty (stores no references).

Returns:
whether or not this SimplePriorityQueue is empty (stores no references)

getSize

public int getSize()
Returns the number of reference this SimplePriorityQueue stores (0 if empty).

Returns:
the number of reference this SimplePriorityQueue stores (0 if empty)

toString

public java.lang.String toString()
Returns a String representation of the state of this SimplePriorityQueue. The String contains the value of rear, the length of the SimplePriorityQueue array, and all the references stored in the pq array.

Overrides:
toString in class java.lang.Object
Returns:
a String representation of the state of this SimplePriorityQueue