public class FixedPrioritiesPriorityQueue<E> extends java.util.AbstractSet<E> implements PriorityQueue<E>, java.util.Iterator<E>, java.io.Serializable, java.lang.Cloneable
BinaryHeapPriorityQueue
and nearly as fast as PriorityQueue
, it does not support removing or changing the
priority of an element. Also, while getPriority(Object key)
is supported, performance will be linear, not
constant.Constructor and Description |
---|
FixedPrioritiesPriorityQueue() |
FixedPrioritiesPriorityQueue(int capacity) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(E key,
double priority)
Adds a key to the queue with the given priority.
|
boolean |
changePriority(E key,
double priority)
Not supported in this implementation.
|
void |
clear() |
FixedPrioritiesPriorityQueue<E> |
clone()
Returns a clone of this priority queue.
|
E |
getFirst()
Returns the highest-priority element without removing it from the
queue.
|
double |
getPriority()
Gets the priority of the highest-priority element of the queue.
|
double |
getPriority(java.lang.Object key)
Note that this method will be linear (not constant) time in this
implementation! Better not to use it.
|
boolean |
hasNext()
Returns true if the priority queue is non-empty
|
java.util.Iterator<E> |
iterator() |
E |
next()
Returns the element in the queue with highest priority, and pops it from
the queue.
|
boolean |
relaxPriority(E key,
double priority)
Not supported in this implementation.
|
void |
remove()
Not supported -- next() already removes the head of the queue.
|
E |
removeFirst()
Returns the highest-priority element and removes it from the queue.
|
int |
size()
Number of elements in the queue.
|
java.util.List<E> |
toSortedList() |
java.lang.String |
toString()
Returns a representation of the queue in decreasing priority order.
|
java.lang.String |
toString(int maxKeysToPrint)
Returns a representation of the queue in decreasing priority order,
displaying at most maxKeysToPrint elements.
|
java.lang.String |
toString(int maxKeysToPrint,
java.lang.String dblFmt)
Returns a representation of the queue in decreasing priority order,
displaying at most maxKeysToPrint elements.
|
add, addAll, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray
finalize, getClass, notify, notifyAll, wait, wait, wait
public FixedPrioritiesPriorityQueue()
public FixedPrioritiesPriorityQueue(int capacity)
public boolean hasNext()
hasNext
in interface java.util.Iterator<E>
public E next() throws java.util.NoSuchElementException
next
in interface java.util.Iterator<E>
java.util.NoSuchElementException
public void remove()
remove
in interface java.util.Iterator<E>
public boolean add(E key, double priority)
add
in interface PriorityQueue<E>
true
if this set did not already contain the specified
element.public boolean changePriority(E key, double priority)
changePriority
in interface PriorityQueue<E>
key
- an E
valuepublic E getFirst()
getFirst
in interface PriorityQueue<E>
public double getPriority(java.lang.Object key)
getPriority
in interface PriorityQueue<E>
key
- The object to assesspublic double getPriority()
getPriority
in interface PriorityQueue<E>
public boolean relaxPriority(E key, double priority)
relaxPriority
in interface PriorityQueue<E>
public E removeFirst() throws java.util.NoSuchElementException
removeFirst
in interface PriorityQueue<E>
java.util.NoSuchElementException
public java.util.List<E> toSortedList()
toSortedList
in interface PriorityQueue<E>
public int size()
public void clear()
public java.util.Iterator<E> iterator()
public java.lang.String toString()
toString
in class java.util.AbstractCollection<E>
public java.lang.String toString(int maxKeysToPrint)
toString
in interface PriorityQueue<E>
maxKeysToPrint
- The maximum number of keys to print. Less are
printed if there are less than this number of items in the
PriorityQueue. If this number is non-positive, then all elements in
the PriorityQueue are printed.public java.lang.String toString(int maxKeysToPrint, java.lang.String dblFmt)
public final FixedPrioritiesPriorityQueue<E> clone()
clone
in class java.lang.Object