public class FixedPrioritiesPriorityQueue<E> extends AbstractSet<E> implements PriorityQueue<E>, Iterator<E>, Serializable, 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(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
|
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.
|
List<E> |
toSortedList() |
String |
toString()
Returns a representation of the queue in decreasing priority order.
|
String |
toString(int maxKeysToPrint)
Returns a representation of the queue in decreasing priority order,
displaying at most maxKeysToPrint elements.
|
String |
toString(int maxKeysToPrint,
String dblFmt)
Returns a representation of the queue in decreasing priority order,
displaying at most maxKeysToPrint elements.
|
equals, hashCode, removeAll
add, addAll, contains, containsAll, isEmpty, remove, retainAll, toArray, toArray
finalize, getClass, notify, notifyAll, wait, wait, wait
add, addAll, contains, containsAll, equals, hashCode, isEmpty, remove, removeAll, retainAll, spliterator, toArray, toArray
parallelStream, removeIf, stream
forEachRemaining
public FixedPrioritiesPriorityQueue()
public FixedPrioritiesPriorityQueue(int capacity)
public boolean hasNext()
public E next() throws NoSuchElementException
next
in interface Iterator<E>
NoSuchElementException
public void remove()
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(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 NoSuchElementException
removeFirst
in interface PriorityQueue<E>
NoSuchElementException
public List<E> toSortedList()
toSortedList
in interface PriorityQueue<E>
public int size()
size
in interface Collection<E>
size
in interface Set<E>
size
in class AbstractCollection<E>
public void clear()
clear
in interface Collection<E>
clear
in interface Set<E>
clear
in class AbstractCollection<E>
public String toString()
toString
in class AbstractCollection<E>
public 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 String toString(int maxKeysToPrint, String dblFmt)
public final FixedPrioritiesPriorityQueue<E> clone()