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>
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a non-priority element to this deque, which will be polled last.voidConvenience 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.Returns an unmodifiable collection view.voidclear()Removes all priority and non-priority elements.booleanReturns whether the given element is contained in this list.booleancontainsPriorityElement(T element) Returns whether the given element is a known priority element.booleangetAndRemove(Predicate<T> preCondition) Find first element matching thePredicate, remove it from thePrioritizedDequeand return it.intReturns the current number of priority elements ([0;size()]).inthashCode()booleanisEmpty()Returns true if there are no elements.iterator()peek()Returns the first priority element or non-priority element if the former does not exist.peekLast()Returns the last non-priority element or priority element if the former does not exist.poll()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()toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
PrioritizedDeque
public PrioritizedDeque()
-
-
Method Details
-
addPriorityElement
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
Adds a non-priority element to this deque, which will be polled last.- Parameters:
element- the element to add
-
add
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
Prioritizes an already existing element. Note that this method assumes identity.- Parameters:
element- the element to prioritize.
-
asUnmodifiableCollection
Returns an unmodifiable collection view. -
getAndRemove
Find first element matching thePredicate, remove it from thePrioritizedDequeand return it.- Returns:
- removed element
-
poll
Polls the first priority element or non-priority element if the former does not exist.- Returns:
- the first element or null.
-
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
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
-
clear
public void clear()Removes all priority and non-priority elements. -
isEmpty
public boolean isEmpty()Returns true if there are no elements. -
contains
Returns whether the given element is contained in this list. Test is performed by identity. -
equals
-
hashCode
public int hashCode() -
toString
-
peekLast
Returns the last non-priority element or priority element if the former does not exist.- Returns:
- the last element or null.
-
stream
-