Package org.apache.mina.util
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:
java.io.Serializable,java.lang.Iterable<E>,java.util.Collection<E>,java.util.List<E>,java.util.Queue<E>
public class CircularQueue<E> extends java.util.AbstractList<E> implements java.util.Queue<E>, java.io.SerializableA unbounded circular queue based on array.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_CAPACITYMinimal size of the underlying arrayprivate intfirstprivate booleanfullprivate intinitialCapacityThe initial capacity of the listprivate java.lang.Object[]itemsprivate intlastprivate intmaskprivate static longserialVersionUIDThe serialVersionUID : mandatory for serializable classesprivate intshrinkThreshold
-
Constructor Summary
Constructors Constructor Description CircularQueue()Construct a new, empty, circular queue.CircularQueue(int initialCapacity)Construct a new circular queue with an initial capacity.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(int idx, E o)booleanadd(E o)intcapacity()private voidcheckIndex(int idx)voidclear()private voiddecreaseSize()Eelement()private voidexpandIfNeeded()Eget(int idx)private intgetRealIndex(int idx)private voidincreaseSize()booleanisEmpty()private static intnormalizeCapacity(int initialCapacity)The capacity must be a power of 2.booleanoffer(E item)Epeek()Epoll()Eremove()Eremove(int idx)Eset(int idx, E o)private voidshrinkIfNeeded()intsize()java.lang.StringtoString()-
Methods inherited from class java.util.AbstractList
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subList
-
Methods inherited from class java.util.AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArray
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
The serialVersionUID : mandatory for serializable classes- See Also:
- Constant Field Values
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITY
Minimal size of the underlying array- See Also:
- Constant Field Values
-
initialCapacity
private final int initialCapacity
The initial capacity of the list
-
items
private volatile java.lang.Object[] items
-
mask
private int mask
-
first
private int first
-
last
private int last
-
full
private boolean full
-
shrinkThreshold
private int shrinkThreshold
-
-
Method Detail
-
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()
-
get
public E get(int idx)
-
isEmpty
public boolean isEmpty()
-
size
public int size()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.util.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)
-
add
public void add(int idx, E o)
-
remove
public E remove(int idx)
-
-