public class BoundedPriorityQueue extends SemaphoreControlledChannel
Put and take operations may throw ClassCastException if elements are not Comparable, or not comparable using the supplied comparator. Since not all elements are compared on each operation it is possible that an exception will not be thrown during insertion of non-comparable element, but will later be encountered during another insertion or extraction.
Modifier and Type | Field and Description |
---|---|
protected Heap |
heap_ |
capacity_, putGuard_, takeGuard_
Constructor and Description |
---|
BoundedPriorityQueue()
Create a priority queue with the current default capacity
and relying on natural ordering.
|
BoundedPriorityQueue(java.util.Comparator comparator)
Create a priority queue with the current default capacity
and the given comparator
|
BoundedPriorityQueue(int capacity)
Create a priority queue with the given capacity,
and relying on natural ordering.
|
BoundedPriorityQueue(int capacity,
java.util.Comparator cmp)
Create a priority queue with the given capacity and comparator
|
BoundedPriorityQueue(int capacity,
java.util.Comparator cmp,
java.lang.Class semaphoreClass)
Create a priority queue with the given capacity and comparator, using
the supplied Semaphore class for semaphores.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.Object |
extract()
Internal mechanics of take.
|
protected void |
insert(java.lang.Object x)
Internal mechanics of put.
|
java.lang.Object |
peek()
Return, but do not remove object at head of Channel,
or null if it is empty.
|
protected final Heap heap_
public BoundedPriorityQueue(int capacity, java.util.Comparator cmp) throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException
- if capacity less or equal to zeropublic BoundedPriorityQueue(java.util.Comparator comparator)
public BoundedPriorityQueue(int capacity)
public BoundedPriorityQueue()
public BoundedPriorityQueue(int capacity, java.util.Comparator cmp, java.lang.Class semaphoreClass) throws java.lang.IllegalArgumentException, java.lang.NoSuchMethodException, java.lang.SecurityException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException
java.lang.IllegalArgumentException
- if capacity less or equal to zerojava.lang.NoSuchMethodException
- If class does not have constructor
that intializes permitsjava.lang.SecurityException
- if constructor information
not accessiblejava.lang.InstantiationException
- if semaphore class is abstractjava.lang.IllegalAccessException
- if constructor cannot be calledjava.lang.reflect.InvocationTargetException
- if semaphore constructor throws an
exceptionprotected void insert(java.lang.Object x)
SemaphoreControlledChannel
insert
in class SemaphoreControlledChannel
protected java.lang.Object extract()
SemaphoreControlledChannel
extract
in class SemaphoreControlledChannel
public java.lang.Object peek()
Channel