Class 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 Detail

      • PrioritizedDeque

        public PrioritizedDeque()
    • 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 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.
      • 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.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode 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()