Class BinaryHeapQueue<T extends Queue.QueueEntry>

java.lang.Object
org.drools.core.util.BinaryHeapQueue<T>
All Implemented Interfaces:
Externalizable, Serializable, Queue<T>

public class BinaryHeapQueue<T extends Queue.QueueEntry> extends Object implements Queue<T>, Externalizable
See Also:
  • Field Details

    • log

      protected static final transient org.slf4j.Logger log
  • Constructor Details

    • BinaryHeapQueue

      public BinaryHeapQueue()
    • BinaryHeapQueue

      public BinaryHeapQueue(Comparator<T> comparator)
      Constructs a new BinaryHeap that 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(Comparator<T> comparator, int capacity)
      Constructs a new BinaryHeap.
      Parameters:
      comparator - the comparator used to order the elements, null means use natural order
      capacity - the initial capacity for the heap
      Throws:
      IllegalArgumentException - if capacity is <= 0
  • Method Details

    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • clear

      public void clear()
      Clears all elements from queue.
      Specified by:
      clear in interface Queue<T extends Queue.QueueEntry>
    • isEmpty

      public boolean isEmpty()
      Tests if queue is empty.
      Specified by:
      isEmpty in interface Queue<T extends Queue.QueueEntry>
      Returns:
      true if queue is empty; false otherwise.
    • isFull

      public boolean isFull()
      Tests if queue is full.
      Returns:
      true if queue is full; false otherwise.
    • size

      public int size()
      Returns the number of elements in this heap.
      Specified by:
      size in interface Queue<T extends Queue.QueueEntry>
      Returns:
      the number of elements in this heap
    • peek

      public T peek()
      Specified by:
      peek in interface Queue<T extends Queue.QueueEntry>
    • enqueue

      public void enqueue(T element)
      Inserts an Queueable into queue.
      Specified by:
      enqueue in interface Queue<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:
      dequeue in interface Queue<T extends Queue.QueueEntry>
      Returns:
      the Queueable at top of heap
      Throws:
      NoSuchElementException - if isEmpty() == true
    • dequeue

      public void dequeue(T activation)
      Specified by:
      dequeue in interface Queue<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 Collection<T> getAll()
      Specified by:
      getAll in interface Queue<T extends Queue.QueueEntry>
    • toString

      public String toString()
      Overrides:
      toString in class Object