Class AbstractLinkedDeque<E>

  • Type Parameters:
    E - the type of elements held in this collection
    All Implemented Interfaces:
    LinkedDeque<E>, java.lang.Iterable<E>, java.util.Collection<E>, java.util.Deque<E>, java.util.Queue<E>
    Direct Known Subclasses:
    AccessOrderDeque, WriteOrderDeque

    @NotThreadSafe
    abstract class AbstractLinkedDeque<E>
    extends java.util.AbstractCollection<E>
    implements LinkedDeque<E>
    This class provides a skeletal implementation of the LinkedDeque interface to minimize the effort required to implement this interface.
    • Field Detail

      • first

        E first
        Pointer to first node. Invariant: (first == null && last == null) || (first.prev == null)
      • last

        E last
        Pointer to last node. Invariant: (first == null && last == null) || (last.next == null)
    • Constructor Detail

      • AbstractLinkedDeque

        AbstractLinkedDeque()
    • Method Detail

      • linkFirst

        void linkFirst​(E e)
        Links the element to the front of the deque so that it becomes the first element.
        Parameters:
        e - the unlinked element
      • linkLast

        void linkLast​(E e)
        Links the element to the back of the deque so that it becomes the last element.
        Parameters:
        e - the unlinked element
      • unlinkFirst

        E unlinkFirst()
        Unlinks the non-null first element.
      • unlinkLast

        E unlinkLast()
        Unlinks the non-null last element.
      • unlink

        void unlink​(E e)
        Unlinks the non-null element.
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<E>
        Overrides:
        isEmpty in class java.util.AbstractCollection<E>
      • checkNotEmpty

        void checkNotEmpty()
      • size

        public int size()

        Beware that, unlike in most collections, this method is NOT a constant-time operation.

        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>
      • clear

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

        public abstract boolean contains​(java.lang.Object o)
        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>
      • isFirst

        public boolean isFirst​(E e)
        Description copied from interface: LinkedDeque
        Returns if the element is at the front of the deque.
        Specified by:
        isFirst in interface LinkedDeque<E>
        Parameters:
        e - the linked element
      • isLast

        public boolean isLast​(E e)
        Description copied from interface: LinkedDeque
        Returns if the element is at the back of the deque.
        Specified by:
        isLast in interface LinkedDeque<E>
        Parameters:
        e - the linked element
      • moveToFront

        public void moveToFront​(E e)
        Description copied from interface: LinkedDeque
        Moves the element to the front of the deque so that it becomes the first element.
        Specified by:
        moveToFront in interface LinkedDeque<E>
        Parameters:
        e - the linked element
      • moveToBack

        public void moveToBack​(E e)
        Description copied from interface: LinkedDeque
        Moves the element to the back of the deque so that it becomes the last element.
        Specified by:
        moveToBack in interface LinkedDeque<E>
        Parameters:
        e - the linked element
      • 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>
      • 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>
      • element

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

        public boolean offer​(E e)
        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>
      • add

        public boolean add​(E e)
        Specified by:
        add in interface java.util.Collection<E>
        Specified by:
        add in interface java.util.Deque<E>
        Specified by:
        add in interface java.util.Queue<E>
        Overrides:
        add in class java.util.AbstractCollection<E>
      • 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>
      • 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>
      • remove

        public E remove()
        Specified by:
        remove in interface java.util.Deque<E>
        Specified by:
        remove in interface java.util.Queue<E>
      • 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>
      • removeAll

        public boolean removeAll​(java.util.Collection<?> c)
        Specified by:
        removeAll in interface java.util.Collection<E>
        Overrides:
        removeAll in class java.util.AbstractCollection<E>
      • push

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

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

        public LinkedDeque.PeekingIterator<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 interface LinkedDeque<E>
        Specified by:
        iterator in class java.util.AbstractCollection<E>