Interface PriorityQueue<K>

All Known Subinterfaces:
BytePriorityQueue, CharPriorityQueue, DoublePriorityQueue, FloatPriorityQueue, IntPriorityQueue, LongPriorityQueue, ShortPriorityQueue
All Known Implementing Classes:
AbstractBytePriorityQueue, AbstractCharPriorityQueue, AbstractDoublePriorityQueue, AbstractFloatPriorityQueue, AbstractIntPriorityQueue, AbstractLongPriorityQueue, AbstractPriorityQueue, AbstractShortPriorityQueue, ByteArrayFIFOQueue, ByteArrayPriorityQueue, ByteHeapPriorityQueue, BytePriorityQueues.SynchronizedPriorityQueue, CharArrayFIFOQueue, CharArrayPriorityQueue, CharHeapPriorityQueue, CharPriorityQueues.SynchronizedPriorityQueue, DoubleArrayFIFOQueue, DoubleArrayPriorityQueue, DoubleHeapPriorityQueue, DoublePriorityQueues.SynchronizedPriorityQueue, FloatArrayFIFOQueue, FloatArrayPriorityQueue, FloatHeapPriorityQueue, FloatPriorityQueues.SynchronizedPriorityQueue, IntArrayFIFOQueue, IntArrayPriorityQueue, IntHeapPriorityQueue, IntPriorityQueues.SynchronizedPriorityQueue, LongArrayFIFOQueue, LongArrayPriorityQueue, LongHeapPriorityQueue, LongPriorityQueues.SynchronizedPriorityQueue, ObjectArrayFIFOQueue, ObjectArrayPriorityQueue, ObjectHeapPriorityQueue, PriorityQueues.EmptyPriorityQueue, PriorityQueues.SynchronizedPriorityQueue, ShortArrayFIFOQueue, ShortArrayPriorityQueue, ShortHeapPriorityQueue, ShortPriorityQueues.SynchronizedPriorityQueue

public interface PriorityQueue<K>
A priority queue.

A priority queue provides a way to enqueue elements, and to dequeue them in some specified order. Elements that are smaller in the specified order are dequeued first. It is also possible to get the first element, that is, the element that would be dequeued next.

Additionally, the queue may provide a method to peek at element that would be dequeued last.

The relative order of the elements enqueued should not change during queue operations. Nonetheless, some implementations may give the caller a way to notify the queue that the first element has changed its relative position in the order.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Notifies the queue that the first element has changed (optional operation).
    void
    Removes all elements from this queue.
    Comparator<? super K>
    Returns the comparator associated with this queue, or null if it uses its elements' natural ordering.
    Dequeues the first element from the queue.
    void
    Enqueues a new element.
    Returns the first element of the queue.
    default boolean
    Checks whether this queue is empty.
    default K
    Returns the last element of the queue, that is, the element the would be dequeued last (optional operation).
    int
    Returns the number of elements in this queue.
  • Method Details

    • enqueue

      void enqueue(K x)
      Enqueues a new element.
      Parameters:
      x - the element to enqueue.
    • dequeue

      K dequeue()
      Dequeues the first element from the queue.
      Returns:
      the dequeued element.
      Throws:
      NoSuchElementException - if the queue is empty.
    • isEmpty

      default boolean isEmpty()
      Checks whether this queue is empty.

      This default implementation checks whether size() is zero.

      Returns:
      true if this queue is empty.
    • size

      int size()
      Returns the number of elements in this queue.
      Returns:
      the number of elements in this queue.
    • clear

      void clear()
      Removes all elements from this queue.
    • first

      K first()
      Returns the first element of the queue.
      Returns:
      the first element.
      Throws:
      NoSuchElementException - if the queue is empty.
    • last

      default K last()
      Returns the last element of the queue, that is, the element the would be dequeued last (optional operation).

      This default implementation just throws an UnsupportedOperationException.

      Returns:
      the last element.
      Throws:
      NoSuchElementException - if the queue is empty.
    • changed

      default void changed()
      Notifies the queue that the first element has changed (optional operation).

      This default implementation just throws an UnsupportedOperationException.

    • comparator

      Comparator<? super K> comparator()
      Returns the comparator associated with this queue, or null if it uses its elements' natural ordering.
      Returns:
      the comparator associated with this sorted set, or null if it uses its elements' natural ordering.