Class FastSizeDeque<E>

  • Type Parameters:
    E - Deque element type
    All Implemented Interfaces:
    Iterable<E>, Collection<E>, Deque<E>, Queue<E>

    public class FastSizeDeque<E>
    extends Object
    implements Deque<E>
    Deque decorator that uses LongAdder for faster size computation.

    Implementation is thread-safe if underlying Deque is thread-safe.

    • Constructor Detail

      • FastSizeDeque

        public FastSizeDeque​(Deque<E> deque)
        Creates a decorator.
        Parameters:
        deque - Deque being decorated.
    • Method Detail

      • sizex

        public int sizex()
        Fast size getter.
        Returns:
        Deque size.
      • isEmptyx

        public boolean isEmptyx()
        Tests this deque for emptiness.; equivalent to sizex() == 0.
        Returns:
        True if this deque is empty.
      • addFirst

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

        public void addLast​(E e)
        Specified by:
        addLast in interface Deque<E>
      • offerFirst

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

        public boolean offerLast​(E e)
        Specified by:
        offerLast in interface Deque<E>
      • removeLast

        public E removeLast()
        Specified by:
        removeLast in interface Deque<E>
      • pollFirst

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

        public E pollLast()
        Specified by:
        pollLast in interface Deque<E>
      • getFirst

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

        public E getLast()
        Specified by:
        getLast in interface Deque<E>
      • peekFirst

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

        public E peekLast()
        Specified by:
        peekLast in interface Deque<E>
      • add

        public boolean add​(E e)
        Specified by:
        add in interface Collection<E>
        Specified by:
        add in interface Deque<E>
        Specified by:
        add in interface Queue<E>
      • offer

        public boolean offer​(E e)
        Specified by:
        offer in interface Deque<E>
        Specified by:
        offer in interface Queue<E>
      • poll

        public E poll()
        Specified by:
        poll in interface Deque<E>
        Specified by:
        poll in interface Queue<E>
      • peek

        public E peek()
        Specified by:
        peek in interface Deque<E>
        Specified by:
        peek in interface Queue<E>
      • push

        public void push​(E e)
        Specified by:
        push in interface Deque<E>
      • pop

        public E pop()
        Specified by:
        pop in interface Deque<E>
      • addAll

        public boolean addAll​(@NotNull
                              @NotNull Collection<? extends E> col)
        Adds all of the elements in the specified collection at the end of this deque.

        Note: If collection being added can mutate concurrently, or underlying deque implementation allows partial insertion, then subsequent calls to size() can report incorrect value.

        Specified by:
        addAll in interface Collection<E>
        Specified by:
        addAll in interface Deque<E>
        Parameters:
        col - The elements to be inserted into this deque.
        Returns:
        true if this deque changed as a result of the call.
      • toArray

        @NotNull
        public <T> @NotNull T[] toArray​(@NotNull
                                        @NotNull T[] ts)
        Specified by:
        toArray in interface Collection<E>