Class PrioritizedDeque<T>

java.lang.Object
org.apache.flink.runtime.io.network.partition.PrioritizedDeque<T>
Type Parameters:
T - the element type.
All Implemented Interfaces:
Iterable<T>

@Internal public final class PrioritizedDeque<T> extends Object implements Iterable<T>
A deque-like data structure that supports prioritization of elements, such they will be polled before any non-priority elements.

Note that all element tests are performed by identity.

  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(T element)
    Adds a non-priority element to this deque, which will be polled last.
    void
    add(T element, boolean priority, boolean prioritize)
    Convenience method for adding an element with optional priority and prior removal.
    void
    Adds a priority element to this deque, such that it will be polled after all existing priority elements but before any non-priority element.
    Returns an unmodifiable collection view.
    void
    Removes all priority and non-priority elements.
    boolean
    contains(T element)
    Returns whether the given element is contained in this list.
    boolean
    Returns whether the given element is a known priority element.
    boolean
     
    getAndRemove(Predicate<T> preCondition)
    Find first element matching the Predicate, remove it from the PrioritizedDeque and return it.
    int
    Returns the current number of priority elements ([0; size()]).
    int
     
    boolean
    Returns true if there are no elements.
     
    Returns the first priority element or non-priority element if the former does not exist.
    Returns the last non-priority element or priority element if the former does not exist.
    Polls the first priority element or non-priority element if the former does not exist.
    void
    prioritize(T element)
    Prioritizes an already existing element.
    int
    Returns the number of priority and non-priority elements.
     
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface java.lang.Iterable

    forEach, spliterator
  • Constructor Details

    • PrioritizedDeque

      public PrioritizedDeque()
  • Method Details

    • addPriorityElement

      public void addPriorityElement(T element)
      Adds a priority element to this deque, such that it will be polled after all existing priority elements but before any non-priority element.
      Parameters:
      element - the element to add
    • add

      public void add(T element)
      Adds a non-priority element to this deque, which will be polled last.
      Parameters:
      element - the element to add
    • add

      public void add(T element, boolean priority, boolean prioritize)
      Convenience method for adding an element with optional priority and prior removal.
      Parameters:
      element - the element to add
      priority - flag indicating if it's a priority or non-priority element
      prioritize - flag that hints that the element is already in this deque, potentially as non-priority element.
    • prioritize

      public void prioritize(T element)
      Prioritizes an already existing element. Note that this method assumes identity.

      Parameters:
      element - the element to prioritize.
    • asUnmodifiableCollection

      public Collection<T> asUnmodifiableCollection()
      Returns an unmodifiable collection view.
    • getAndRemove

      public T getAndRemove(Predicate<T> preCondition)
      Find first element matching the Predicate, remove it from the PrioritizedDeque and return it.
      Returns:
      removed element
    • poll

      @Nullable public T poll()
      Polls the first priority element or non-priority element if the former does not exist.
      Returns:
      the first element or null.
    • peek

      @Nullable public T peek()
      Returns the first priority element or non-priority element if the former does not exist.
      Returns:
      the first element or null.
    • getNumPriorityElements

      public int getNumPriorityElements()
      Returns the current number of priority elements ([0; size()]).
    • containsPriorityElement

      public boolean containsPriorityElement(T element)
      Returns whether the given element is a known priority element. Test is performed by identity.
    • size

      public int size()
      Returns the number of priority and non-priority elements.
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Iterable<T>
      Returns:
      read-only iterator
    • clear

      public void clear()
      Removes all priority and non-priority elements.
    • isEmpty

      public boolean isEmpty()
      Returns true if there are no elements.
    • contains

      public boolean contains(T element)
      Returns whether the given element is contained in this list. Test is performed by identity.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • peekLast

      @Nullable public T peekLast()
      Returns the last non-priority element or priority element if the former does not exist.
      Returns:
      the last element or null.
    • stream

      public Stream<T> stream()