Class DefaultPriorityQueue<T extends PriorityQueueNode>

java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractQueue<T>
io.netty.util.internal.DefaultPriorityQueue<T>
Type Parameters:
T - The object that is maintained in the queue.
All Implemented Interfaces:
PriorityQueue<T>, java.lang.Iterable<T>, java.util.Collection<T>, java.util.Queue<T>

public final class DefaultPriorityQueue<T extends PriorityQueueNode> extends java.util.AbstractQueue<T> implements PriorityQueue<T>
A priority queue which uses natural ordering of elements. Elements are also required to be of type PriorityQueueNode for the purpose of maintaining the index in the priority queue.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final java.util.Comparator<T>
     
    private static final PriorityQueueNode[]
     
    private T[]
     
    private int
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    DefaultPriorityQueue(java.util.Comparator<T> comparator, int initialSize)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private void
    bubbleDown(int k, T node)
     
    private void
    bubbleUp(int k, T node)
     
    void
     
    void
    Removes all of the elements from this PriorityQueue without calling PriorityQueueNode.priorityQueueIndex(DefaultPriorityQueue) or explicitly removing references to them to allow them to be garbage collected.
    private boolean
     
    boolean
    contains(java.lang.Object o)
     
    boolean
    Same as Collection.contains(Object) but typed using generics.
    boolean
     
    java.util.Iterator<T>
    This iterator does not return elements in any particular order.
    boolean
    offer(T e)
     
     
     
    void
    Notify the queue that the priority for node has changed.
    boolean
    remove(java.lang.Object o)
     
    boolean
    removeTyped(T node)
    Same as Collection.remove(Object) but typed using generics.
    int
     
    java.lang.Object[]
     
    <X> X[]
    toArray(X[] a)
     

    Methods inherited from class java.util.AbstractQueue

    add, addAll, element, remove

    Methods inherited from class java.util.AbstractCollection

    containsAll, removeAll, retainAll, toString

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.util.Collection

    addAll, containsAll, equals, hashCode, parallelStream, removeAll, removeIf, retainAll, spliterator, stream

    Methods inherited from interface java.lang.Iterable

    forEach

    Methods inherited from interface java.util.Queue

    add, element, remove
  • Field Details

  • Constructor Details

    • DefaultPriorityQueue

      public DefaultPriorityQueue(java.util.Comparator<T> comparator, int initialSize)
  • Method Details

    • size

      public int size()
      Specified by:
      size in interface java.util.Collection<T extends PriorityQueueNode>
      Specified by:
      size in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface java.util.Collection<T extends PriorityQueueNode>
      Overrides:
      isEmpty in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • contains

      public boolean contains(java.lang.Object o)
      Specified by:
      contains in interface java.util.Collection<T extends PriorityQueueNode>
      Overrides:
      contains in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • containsTyped

      public boolean containsTyped(T node)
      Description copied from interface: PriorityQueue
      Same as Collection.contains(Object) but typed using generics.
      Specified by:
      containsTyped in interface PriorityQueue<T extends PriorityQueueNode>
    • clear

      public void clear()
      Specified by:
      clear in interface java.util.Collection<T extends PriorityQueueNode>
      Overrides:
      clear in class java.util.AbstractQueue<T extends PriorityQueueNode>
    • clearIgnoringIndexes

      public void clearIgnoringIndexes()
      Description copied from interface: PriorityQueue
      Removes all of the elements from this PriorityQueue without calling PriorityQueueNode.priorityQueueIndex(DefaultPriorityQueue) or explicitly removing references to them to allow them to be garbage collected. This should only be used when it is certain that the nodes will not be re-inserted into this or any other PriorityQueue and it is known that the PriorityQueue itself will be garbage collected after this call.
      Specified by:
      clearIgnoringIndexes in interface PriorityQueue<T extends PriorityQueueNode>
    • offer

      public boolean offer(T e)
      Specified by:
      offer in interface java.util.Queue<T extends PriorityQueueNode>
    • poll

      public T poll()
      Specified by:
      poll in interface java.util.Queue<T extends PriorityQueueNode>
    • peek

      public T peek()
      Specified by:
      peek in interface java.util.Queue<T extends PriorityQueueNode>
    • remove

      public boolean remove(java.lang.Object o)
      Specified by:
      remove in interface java.util.Collection<T extends PriorityQueueNode>
      Overrides:
      remove in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • removeTyped

      public boolean removeTyped(T node)
      Description copied from interface: PriorityQueue
      Same as Collection.remove(Object) but typed using generics.
      Specified by:
      removeTyped in interface PriorityQueue<T extends PriorityQueueNode>
    • priorityChanged

      public void priorityChanged(T node)
      Description copied from interface: PriorityQueue
      Notify the queue that the priority for node has changed. The queue will adjust to ensure the priority queue properties are maintained.
      Specified by:
      priorityChanged in interface PriorityQueue<T extends PriorityQueueNode>
      Parameters:
      node - An object which is in this queue and the priority may have changed.
    • toArray

      public java.lang.Object[] toArray()
      Specified by:
      toArray in interface java.util.Collection<T extends PriorityQueueNode>
      Overrides:
      toArray in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • toArray

      public <X> X[] toArray(X[] a)
      Specified by:
      toArray in interface java.util.Collection<T extends PriorityQueueNode>
      Overrides:
      toArray in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • iterator

      public java.util.Iterator<T> iterator()
      This iterator does not return elements in any particular order.
      Specified by:
      iterator in interface java.util.Collection<T extends PriorityQueueNode>
      Specified by:
      iterator in interface java.lang.Iterable<T extends PriorityQueueNode>
      Specified by:
      iterator in class java.util.AbstractCollection<T extends PriorityQueueNode>
    • contains

      private boolean contains(PriorityQueueNode node, int i)
    • bubbleDown

      private void bubbleDown(int k, T node)
    • bubbleUp

      private void bubbleUp(int k, T node)