gshute.util
Class ListPriorityQueue

java.lang.Object
  |
  +--gshute.util.ListPriorityQueue

public class ListPriorityQueue
extends java.lang.Object
implements PriorityQueue

A ListPriorityQueue is an implementation of the PriorityQueue interface using a java.util.ArrayList.


Inner Class Summary
 class ListPriorityQueue.Entry
           
 
Field Summary
protected  java.util.Comparator comparator
          comparator is the comparator for priorities in this priority queue.
protected  java.util.ArrayList entries
          entries is the list of entries for this priority queue.
 
Constructor Summary
protected ListPriorityQueue()
          This constructor is disabled.
  ListPriorityQueue(java.util.Comparator c)
          new ListPriorityQueue(c) returns a priority queue that uses c for comparing priorities.
 
Method Summary
 void add(java.lang.Object dat, java.lang.Object pri)
          pq.add(dat, pri) adds dat to pq with priority pri.
protected  int addIndex(java.lang.Object pri)
          addIndex(pri) returns the index at which pri should be added to this priority queue.
 void clear()
          pq.clear() removes all entries from pq.
 java.lang.Object data()
          pq.data() returns the highest priority data in pq.
 java.util.Iterator iterator()
          pq.iterator() returns an iterator for the entries of pq.
 boolean more()
          pq.more() returns true if there are more entries in pq.
 java.lang.Object priority()
          pq.priority() returns the priority of the highest priority entry in pq.
 void remove()
          pq.remove() removes the highest priority entry from pq.
 int size()
          pq.size() returns the number of entries in pq.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entries

protected java.util.ArrayList entries
entries is the list of entries for this priority queue.

comparator

protected java.util.Comparator comparator
comparator is the comparator for priorities in this priority queue.
Constructor Detail

ListPriorityQueue

protected ListPriorityQueue()
This constructor is disabled.

ListPriorityQueue

public ListPriorityQueue(java.util.Comparator c)
new ListPriorityQueue(c) returns a priority queue that uses c for comparing priorities.
Method Detail

more

public boolean more()
pq.more() returns true if there are more entries in pq.
Specified by:
more in interface PriorityQueue

size

public int size()
pq.size() returns the number of entries in pq.
Specified by:
size in interface PriorityQueue

add

public void add(java.lang.Object dat,
                java.lang.Object pri)
pq.add(dat, pri) adds dat to pq with priority pri.
Specified by:
add in interface PriorityQueue

data

public java.lang.Object data()
pq.data() returns the highest priority data in pq.

Precondition: pq.more() is true

Specified by:
data in interface PriorityQueue

priority

public java.lang.Object priority()
pq.priority() returns the priority of the highest priority entry in pq.

Precondition: pq.more() is true

Specified by:
priority in interface PriorityQueue

remove

public void remove()
pq.remove() removes the highest priority entry from pq.

Precondition: pq.more() is true

Specified by:
remove in interface PriorityQueue

clear

public void clear()
pq.clear() removes all entries from pq.
Specified by:
clear in interface PriorityQueue

iterator

public java.util.Iterator iterator()
pq.iterator() returns an iterator for the entries of pq.
Specified by:
iterator in interface PriorityQueue

addIndex

protected int addIndex(java.lang.Object pri)
addIndex(pri) returns the index at which pri should be added to this priority queue.