Class CircularQueue<E>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractList<E>
org.apache.mina.util.CircularQueue<E>
Type Parameters:
E - The type of elements stored inthe queue
All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, List<E>, Queue<E>

public class CircularQueue<E> extends AbstractList<E> implements Queue<E>, Serializable
A unbounded circular queue based on array.
See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      The serialVersionUID : mandatory for serializable classes
      See Also:
    • DEFAULT_CAPACITY

      private static final int DEFAULT_CAPACITY
      Minimal size of the underlying array
      See Also:
    • initialCapacity

      private final int initialCapacity
      The initial capacity of the list
    • items

      private volatile Object[] items
    • mask

      private int mask
    • first

      private int first
    • last

      private int last
    • full

      private boolean full
    • shrinkThreshold

      private int shrinkThreshold
  • Constructor Details

    • CircularQueue

      public CircularQueue()
      Construct a new, empty, circular queue.
    • CircularQueue

      public CircularQueue(int initialCapacity)
      Construct a new circular queue with an initial capacity.
      Parameters:
      initialCapacity - The initial capacity of this circular queue
  • Method Details

    • normalizeCapacity

      private static int normalizeCapacity(int initialCapacity)
      The capacity must be a power of 2.
    • capacity

      public int capacity()
      Returns:
      the capacity of this queue.
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<E>
      Specified by:
      clear in interface List<E>
      Overrides:
      clear in class AbstractList<E>
    • poll

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

      public boolean offer(E item)
      Specified by:
      offer in interface Queue<E>
    • peek

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

      public E get(int idx)
      Specified by:
      get in interface List<E>
      Specified by:
      get in class AbstractList<E>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<E>
      Specified by:
      isEmpty in interface List<E>
      Overrides:
      isEmpty in class AbstractCollection<E>
    • size

      public int size()
      Specified by:
      size in interface Collection<E>
      Specified by:
      size in interface List<E>
      Specified by:
      size in class AbstractCollection<E>
    • toString

      public String toString()
      Overrides:
      toString in class AbstractCollection<E>
    • checkIndex

      private void checkIndex(int idx)
    • getRealIndex

      private int getRealIndex(int idx)
    • increaseSize

      private void increaseSize()
    • decreaseSize

      private void decreaseSize()
    • expandIfNeeded

      private void expandIfNeeded()
    • shrinkIfNeeded

      private void shrinkIfNeeded()
    • add

      public boolean add(E o)
      Specified by:
      add in interface Collection<E>
      Specified by:
      add in interface List<E>
      Specified by:
      add in interface Queue<E>
      Overrides:
      add in class AbstractList<E>
    • set

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

      public void add(int idx, E o)
      Specified by:
      add in interface List<E>
      Overrides:
      add in class AbstractList<E>
    • remove

      public E remove(int idx)
      Specified by:
      remove in interface List<E>
      Overrides:
      remove in class AbstractList<E>
    • remove

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

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