T
- the type of elements contained in this PriorityQueue
.public class AdjustablePriorityQueue<T>
extends java.util.AbstractQueue<T>
getPriority(Object)
and setPriority(Object, double)
methods, therefore the elements in the queue must be unique and the notion of
equality used to access them must be identity (==
), in constrast to
PriorityQueue
, which relies on the natural ordering of the
elements or a supplied Comparator
. An attempt to insert an
element that is already there results in an IllegalArgumentException
.Constructor and Description |
---|
AdjustablePriorityQueue()
Constructs a
PriorityQueue min queue. |
AdjustablePriorityQueue(boolean orientation)
Constructs a
PriorityQueue that extracts elements according to
priority. |
Modifier and Type | Method and Description |
---|---|
boolean |
contains(java.lang.Object item)
Tests whether the data structure contains the given item.
|
double |
getPriority(T item)
Gets the current priority of the given item.
|
java.util.Iterator<T> |
iterator()
See
Collection.iterator() . |
boolean |
offer(T item)
Inserts an item with the default priority:
Double.POSITIVE_INFINITY for a min queue,
Double.NEGATIVE_INFINITY for a max queue. |
T |
peek()
See
Queue.peek() . |
T |
poll()
See
Queue.poll() . |
void |
setPriority(T item,
double newPriority)
Sets the priority of the given item.
|
int |
size()
See
Collection.size() . |
containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
public AdjustablePriorityQueue(boolean orientation)
PriorityQueue
that extracts elements according to
priority. Priorities are doubles that are supplied in the constructor, but
can be changed in situ. The priority queue can be either a max queue
(extract max supported) or a min queue (extract min supported) depending
on the value of the parameter.orientation
- the orientation of the queue - true=min, false=max.public AdjustablePriorityQueue()
PriorityQueue
min queue. The element with the
smallest priority value is the next extracted.public boolean offer(T item)
Double.POSITIVE_INFINITY
for a min queue,
Double.NEGATIVE_INFINITY
for a max queue.item
- the item to insertjava.lang.IllegalArgumentException
- if the item is already in the queuepublic boolean contains(java.lang.Object item)
public T poll()
Queue.poll()
.public T peek()
Queue.peek()
.public double getPriority(T item) throws java.util.NoSuchElementException
item
- the itemjava.util.NoSuchElementException
- if the item is not in the queuepublic void setPriority(T item, double newPriority) throws java.util.NoSuchElementException
item
- the item to be adjustednewPriority
- the new priorityjava.util.NoSuchElementException
- if the item is not in the queuepublic int size()
Collection.size()
.