Class ArrayQueue<E>

  • Type Parameters:
    E - the type of object the queue holds
    All Implemented Interfaces:
    Iterable<E>, Collection<E>, List<E>, Queue<E>

    public class ArrayQueue<E>
    extends AbstractList<E>
    implements Queue<E>
    Queue backed by circular array.

    This partial Queue implementation (also with remove() for stack operation) is backed by a growable circular array.

    • Field Detail

      • _lock

        protected final Object _lock
      • _growCapacity

        protected final int _growCapacity
      • _elements

        protected Object[] _elements
      • _nextE

        protected int _nextE
      • _nextSlot

        protected int _nextSlot
      • _size

        protected int _size
    • Constructor Detail

      • ArrayQueue

        public ArrayQueue()
      • ArrayQueue

        public ArrayQueue​(Object lock)
      • ArrayQueue

        public ArrayQueue​(int capacity)
      • ArrayQueue

        public ArrayQueue​(int initCapacity,
                          int growBy)
      • ArrayQueue

        public ArrayQueue​(int initCapacity,
                          int growBy,
                          Object lock)
    • Method Detail

      • getCapacity

        public int getCapacity()
      • getNextSlotUnsafe

        public int getNextSlotUnsafe()
        Returns:
        the next slot to be used
      • offer

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

        protected boolean enqueue​(E e)
      • addUnsafe

        public void addUnsafe​(E e)
        Add without synchronization or bounds checking
        Parameters:
        e - the element to add
        See Also:
        add(Object)
      • element

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

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

        public E peekUnsafe()
      • poll

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

        public E pollUnsafe()
      • dequeue

        protected E dequeue()
      • remove

        public E remove()
        Specified by:
        remove in interface Queue<E>
      • sizeUnsafe

        public int sizeUnsafe()
      • getUnsafe

        public E getUnsafe​(int index)
        Get without synchronization or bounds checking.
        Parameters:
        index - index of the element to return
        Returns:
        the element at the specified index
        See Also:
        get(int)
      • set

        public E set​(int index,
                     E element)
        Specified by:
        set in interface List<E>
        Overrides:
        set in class AbstractList<E>
      • add

        public void add​(int index,
                        E element)
        Specified by:
        add in interface List<E>
        Overrides:
        add in class AbstractList<E>
      • resizeUnsafe

        protected void resizeUnsafe​(int newCapacity)
      • growUnsafe

        protected boolean growUnsafe()