E
- type of the elementpublic class BoundedPriorityQueue<E>
extends java.util.AbstractQueue<E>
implements java.io.Serializable
PriorityQueue
.
Note: elements are returned in reverse order.
For instance, if "top N smallest elements" are required, use new BoundedPriorityQueue(N)
,
and the elements would be returned in largest to smallest order.Modifier and Type | Field and Description |
---|---|
private java.util.Comparator<? super E> |
comparator |
private int |
maxSize |
private java.util.Queue<E> |
queue |
private static long |
serialVersionUID |
Constructor and Description |
---|
BoundedPriorityQueue(int maxSize)
Creates a bounded priority queue with the specified maximum size and default ordering.
|
BoundedPriorityQueue(int maxSize,
java.util.Comparator<? super E> comparator)
Creates a bounded priority queue with the specified maximum size.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e) |
java.util.Iterator<E> |
iterator() |
boolean |
offer(E e) |
E |
peek() |
E |
poll() |
private static <E> java.util.Comparator<? super E> |
reverse(java.util.Comparator<? super E> comparator)
Internal queue should be in fact in reverse order.
|
int |
size() |
contains, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
private static final long serialVersionUID
private final int maxSize
private final java.util.Comparator<? super E> comparator
private final java.util.Queue<E> queue
public BoundedPriorityQueue(int maxSize)
maxSize
smallest elements would be kept in the queue.maxSize
- maximum size of the queuepublic BoundedPriorityQueue(int maxSize, java.util.Comparator<? super E> comparator)
maxSize
smallest elements would be kept in the queue.maxSize
- maximum size of the queuecomparator
- comparator that orders the elementsprivate static <E> java.util.Comparator<? super E> reverse(java.util.Comparator<? super E> comparator)
E
- type of the elementcomparator
- comparator that designates ordering of the entries or null
for default orderingpublic boolean add(E e)
public java.util.Iterator<E> iterator()