Package org.drools.core.util
Class BinaryHeapQueue<T extends Queue.QueueEntry>
- java.lang.Object
-
- org.drools.core.util.BinaryHeapQueue<T>
-
- All Implemented Interfaces:
java.io.Externalizable,java.io.Serializable,Queue<T>
public class BinaryHeapQueue<T extends Queue.QueueEntry> extends java.lang.Object implements Queue<T>, java.io.Externalizable
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.drools.core.util.Queue
Queue.QueueEntry
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.slf4j.Loggerlog
-
Constructor Summary
Constructors Constructor Description BinaryHeapQueue()BinaryHeapQueue(java.util.Comparator<T> comparator)Constructs a newBinaryHeapthat will use the given comparator to order its elements.BinaryHeapQueue(java.util.Comparator<T> comparator, int capacity)Constructs a newBinaryHeap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears all elements from queue.Tdequeue()Returns the Queueable on top of heap and remove it.voiddequeue(T activation)voidenqueue(T element)Inserts an Queueable into queue.java.util.Collection<T>getAll()booleanisEmpty()Tests if queue is empty.booleanisFull()Tests if queue is full.Tpeek()protected voidpercolateDownMaxHeap(int index)Percolates element down heap from the position given by the index.protected voidpercolateUpMaxHeap(int index)Percolates element up heap from the position given by the index.protected voidpercolateUpMaxHeap(T element)Percolates a new element up heap from the bottom.voidreadExternal(java.io.ObjectInput in)intsize()Returns the number of elements in this heap.java.lang.StringtoString()voidwriteExternal(java.io.ObjectOutput out)
-
-
-
Constructor Detail
-
BinaryHeapQueue
public BinaryHeapQueue()
-
BinaryHeapQueue
public BinaryHeapQueue(java.util.Comparator<T> comparator)
Constructs a newBinaryHeapthat will use the given comparator to order its elements.- Parameters:
comparator- the comparator used to order the elements, null means use natural order
-
BinaryHeapQueue
public BinaryHeapQueue(java.util.Comparator<T> comparator, int capacity)
Constructs a newBinaryHeap.- Parameters:
comparator- the comparator used to order the elements, null means use natural ordercapacity- the initial capacity for the heap- Throws:
java.lang.IllegalArgumentException- ifcapacityis <=0
-
-
Method Detail
-
readExternal
public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException- Specified by:
readExternalin interfacejava.io.Externalizable- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
writeExternal
public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException- Specified by:
writeExternalin interfacejava.io.Externalizable- Throws:
java.io.IOException
-
clear
public void clear()
Clears all elements from queue.- Specified by:
clearin interfaceQueue<T extends Queue.QueueEntry>
-
isEmpty
public boolean isEmpty()
Tests if queue is empty.- Specified by:
isEmptyin interfaceQueue<T extends Queue.QueueEntry>- Returns:
trueif queue is empty;falseotherwise.
-
isFull
public boolean isFull()
Tests if queue is full.- Returns:
trueif queue is full;falseotherwise.
-
size
public int size()
Returns the number of elements in this heap.- Specified by:
sizein interfaceQueue<T extends Queue.QueueEntry>- Returns:
- the number of elements in this heap
-
peek
public T peek()
- Specified by:
peekin interfaceQueue<T extends Queue.QueueEntry>
-
enqueue
public void enqueue(T element)
Inserts an Queueable into queue.- Specified by:
enqueuein interfaceQueue<T extends Queue.QueueEntry>- Parameters:
element- the Queueable to be inserted
-
dequeue
public T dequeue()
Returns the Queueable on top of heap and remove it.- Specified by:
dequeuein interfaceQueue<T extends Queue.QueueEntry>- Returns:
- the Queueable at top of heap
- Throws:
java.util.NoSuchElementException- ifisEmpty() == true
-
dequeue
public void dequeue(T activation)
- Specified by:
dequeuein interfaceQueue<T extends Queue.QueueEntry>
-
percolateDownMaxHeap
protected void percolateDownMaxHeap(int index)
Percolates element down heap from the position given by the index.Assumes it is a maximum heap.
- Parameters:
index- the index of the element
-
percolateUpMaxHeap
protected void percolateUpMaxHeap(int index)
Percolates element up heap from the position given by the index.Assume it is a maximum heap.
- Parameters:
index- the index of the element to be percolated up
-
percolateUpMaxHeap
protected void percolateUpMaxHeap(T element)
Percolates a new element up heap from the bottom.Assume it is a maximum heap.
- Parameters:
element- the element
-
getAll
public java.util.Collection<T> getAll()
- Specified by:
getAllin interfaceQueue<T extends Queue.QueueEntry>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-