Class PriorityDeque<E>

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Deque<E>, java.util.Queue<E>

    public class PriorityDeque<E>
    extends java.util.AbstractQueue<E>
    implements java.util.Deque<E>, java.io.Serializable
    See Also:
    Serialized Form
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addFirst​(E e)  
      void addLast​(E e)  
      void clear()  
      java.util.Comparator<? super E> comparator()
      Returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.
      boolean contains​(java.lang.Object o)
      Returns true if this queue contains the specified element.
      java.util.Iterator<E> descendingIterator()  
      E getFirst()  
      E getLast()  
      java.util.Iterator<E> iterator()  
      boolean offer​(E element)  
      boolean offerFirst​(E e)  
      boolean offerLast​(E e)  
      E peek()  
      E peekFirst()  
      E peekLast()  
      E poll()  
      E pollFirst()  
      E pollLast()  
      E pop()  
      void push​(E e)  
      E remove()  
      boolean remove​(java.lang.Object o)
      Removes a single instance of the specified element from this queue, if it is present.
      E removeFirst()  
      boolean removeFirstOccurrence​(java.lang.Object o)  
      E removeLast()  
      boolean removeLastOccurrence​(java.lang.Object o)  
      int size()  
      java.lang.Object[] toArray()
      Returns an array containing all of the elements in this queue.
      <T> T[] toArray​(T[] a)
      Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array.
      • Methods inherited from class java.util.AbstractQueue

        add, addAll, element
      • Methods inherited from class java.util.AbstractCollection

        containsAll, isEmpty, removeAll, retainAll, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.util.Collection

        containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray
      • Methods inherited from interface java.util.Deque

        add, addAll, element
      • Methods inherited from interface java.lang.Iterable

        forEach
    • Constructor Detail

      • PriorityDeque

        public PriorityDeque()
      • PriorityDeque

        public PriorityDeque​(java.util.Collection<? extends E> c)
      • PriorityDeque

        public PriorityDeque​(int initialCapacity)
      • PriorityDeque

        public PriorityDeque​(int initialCapacity,
                             java.util.Comparator<? super E> comparator)
      • PriorityDeque

        public PriorityDeque​(PriorityDeque<? extends E> c)
      • PriorityDeque

        public PriorityDeque​(java.util.SortedSet<? extends E> c)
    • Method Detail

      • addFirst

        public void addFirst​(E e)
        Specified by:
        addFirst in interface java.util.Deque<E>
      • addLast

        public void addLast​(E e)
        Specified by:
        addLast in interface java.util.Deque<E>
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<E>
        Overrides:
        clear in class java.util.AbstractQueue<E>
      • comparator

        public java.util.Comparator<? super E> comparator()
        Returns the comparator used to order the elements in this queue, or null if this queue is sorted according to the natural ordering of its elements.
        Returns:
        the comparator used to order this queue, or null if this queue is sorted according to the natural ordering of its elements
      • contains

        public boolean contains​(java.lang.Object o)
        Returns true if this queue contains the specified element. More formally, returns true if and only if this queue contains at least one element e such that o.equals(e).
        Specified by:
        contains in interface java.util.Collection<E>
        Specified by:
        contains in interface java.util.Deque<E>
        Overrides:
        contains in class java.util.AbstractCollection<E>
        Parameters:
        o - object to be checked for containment in this queue
        Returns:
        true if this queue contains the specified element
      • descendingIterator

        public java.util.Iterator<E> descendingIterator()
        Specified by:
        descendingIterator in interface java.util.Deque<E>
      • getFirst

        public E getFirst()
        Specified by:
        getFirst in interface java.util.Deque<E>
      • getLast

        public E getLast()
        Specified by:
        getLast in interface java.util.Deque<E>
      • iterator

        public java.util.Iterator<E> iterator()
        Specified by:
        iterator in interface java.util.Collection<E>
        Specified by:
        iterator in interface java.util.Deque<E>
        Specified by:
        iterator in interface java.lang.Iterable<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>
      • offer

        public boolean offer​(E element)
        Specified by:
        offer in interface java.util.Deque<E>
        Specified by:
        offer in interface java.util.Queue<E>
      • offerFirst

        public boolean offerFirst​(E e)
        Specified by:
        offerFirst in interface java.util.Deque<E>
      • offerLast

        public boolean offerLast​(E e)
        Specified by:
        offerLast in interface java.util.Deque<E>
      • peek

        public E peek()
        Specified by:
        peek in interface java.util.Deque<E>
        Specified by:
        peek in interface java.util.Queue<E>
      • peekFirst

        public E peekFirst()
        Specified by:
        peekFirst in interface java.util.Deque<E>
      • peekLast

        public E peekLast()
        Specified by:
        peekLast in interface java.util.Deque<E>
      • poll

        public E poll()
        Specified by:
        poll in interface java.util.Deque<E>
        Specified by:
        poll in interface java.util.Queue<E>
      • pollFirst

        public E pollFirst()
        Specified by:
        pollFirst in interface java.util.Deque<E>
      • pollLast

        public E pollLast()
        Specified by:
        pollLast in interface java.util.Deque<E>
      • pop

        public E pop()
        Specified by:
        pop in interface java.util.Deque<E>
      • push

        public void push​(E e)
        Specified by:
        push in interface java.util.Deque<E>
      • remove

        public E remove()
        Specified by:
        remove in interface java.util.Deque<E>
        Specified by:
        remove in interface java.util.Queue<E>
        Overrides:
        remove in class java.util.AbstractQueue<E>
      • remove

        public boolean remove​(java.lang.Object o)
        Removes a single instance of the specified element from this queue, if it is present. More formally, removes an element e such that o.equals(e), if this queue contains one or more such elements. Returns true if and only if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).
        Specified by:
        remove in interface java.util.Collection<E>
        Specified by:
        remove in interface java.util.Deque<E>
        Overrides:
        remove in class java.util.AbstractCollection<E>
        Parameters:
        o - element to be removed from this queue, if present
        Returns:
        true if this queue changed as a result of the call
      • removeFirst

        public E removeFirst()
        Specified by:
        removeFirst in interface java.util.Deque<E>
      • removeFirstOccurrence

        public boolean removeFirstOccurrence​(java.lang.Object o)
        Specified by:
        removeFirstOccurrence in interface java.util.Deque<E>
      • removeLast

        public E removeLast()
        Specified by:
        removeLast in interface java.util.Deque<E>
      • removeLastOccurrence

        public boolean removeLastOccurrence​(java.lang.Object o)
        Specified by:
        removeLastOccurrence in interface java.util.Deque<E>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<E>
        Specified by:
        size in interface java.util.Deque<E>
        Specified by:
        size in class java.util.AbstractCollection<E>
      • toArray

        public java.lang.Object[] toArray()
        Returns an array containing all of the elements in this queue. The elements are in no particular order.

        The returned array will be "safe" in that no references to it are maintained by this queue. (In other words, this method must allocate a new array). The caller is thus free to modify the returned array.

        This method acts as bridge between array-based and collection-based APIs.

        Specified by:
        toArray in interface java.util.Collection<E>
        Overrides:
        toArray in class java.util.AbstractCollection<E>
        Returns:
        an array containing all of the elements in this queue
      • toArray

        public <T> T[] toArray​(T[] a)
        Returns an array containing all of the elements in this queue; the runtime type of the returned array is that of the specified array. The returned array elements are in no particular order. If the queue fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this queue.

        If the queue fits in the specified array with room to spare (i.e., the array has more elements than the queue), the element in the array immediately following the end of the collection is set to null.

        Like the toArray() method, this method acts as bridge between array-based and collection-based APIs. Further, this method allows precise control over the runtime type of the output array, and may, under certain circumstances, be used to save allocation costs.

        Suppose x is a queue known to contain only strings. The following code can be used to dump the queue into a newly allocated array of String:

         String[] y = x.toArray(new String[0]);
         
        Note that toArray(new Object[0]) is identical in function to toArray().
        Specified by:
        toArray in interface java.util.Collection<E>
        Overrides:
        toArray in class java.util.AbstractCollection<E>
        Parameters:
        a - the array into which the elements of the queue are to be stored, if it is big enough; otherwise, a new array of the same runtime type is allocated for this purpose.
        Returns:
        an array containing all of the elements in this queue
        Throws:
        java.lang.ArrayStoreException - if the runtime type of the specified array is not a supertype of the runtime type of every element in this queue
        java.lang.NullPointerException - if the specified array is null