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 PrioritizedDeque()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(T element)Adds a non-priority element to this deque, which will be polled last.voidadd(T element, boolean priority, boolean prioritize)Convenience method for adding an element with optional priority and prior removal.voidaddPriorityElement(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.Collection<T>asUnmodifiableCollection()Returns an unmodifiable collection view.voidclear()Removes all priority and non-priority elements.booleancontains(T element)Returns whether the given element is contained in this list.booleancontainsPriorityElement(T element)Returns whether the given element is a known priority element.booleanequals(Object o)TgetAndRemove(Predicate<T> preCondition)Find first element matching thePredicate, remove it from thePrioritizedDequeand return it.intgetNumPriorityElements()Returns the current number of priority elements ([0;size()]).inthashCode()booleanisEmpty()Returns true if there are no elements.Iterator<T>iterator()Tpeek()Returns the first priority element or non-priority element if the former does not exist.TpeekLast()Returns the last non-priority element or priority element if the former does not exist.Tpoll()Polls the first priority element or non-priority element if the former does not exist.voidprioritize(T element)Prioritizes an already existing element.intsize()Returns the number of priority and non-priority elements.Stream<T>stream()StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
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 addpriority- flag indicating if it's a priority or non-priority elementprioritize- 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 thePredicate, remove it from thePrioritizedDequeand 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.
-
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.
-
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.
-
-