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>
A unbounded circular queue based on array.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intMinimal size of the underlying arrayprivate intprivate booleanprivate final intThe initial capacity of the listprivate Object[]private intprivate intprivate static final longThe serialVersionUID : mandatory for serializable classesprivate intFields inherited from class AbstractList
modCount -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new, empty, circular queue.CircularQueue(int initialCapacity) Construct a new circular queue with an initial capacity. -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanintcapacity()private voidcheckIndex(int idx) voidclear()private voidelement()private voidget(int idx) private intgetRealIndex(int idx) private voidbooleanisEmpty()private static intnormalizeCapacity(int initialCapacity) The capacity must be a power of 2.booleanpeek()poll()remove()remove(int idx) private voidintsize()toString()Methods inherited from class AbstractList
addAll, equals, hashCode, indexOf, iterator, lastIndexOf, listIterator, listIterator, removeRange, subListMethods inherited from class AbstractCollection
addAll, contains, containsAll, remove, removeAll, retainAll, toArray, toArrayMethods inherited from interface Collection
parallelStream, removeIf, streamMethods inherited from interface List
addAll, contains, containsAll, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDThe serialVersionUID : mandatory for serializable classes- See Also:
-
DEFAULT_CAPACITY
private static final int DEFAULT_CAPACITYMinimal size of the underlying array- See Also:
-
initialCapacity
private final int initialCapacityThe initial capacity of the list -
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:
clearin interfaceCollection<E>- Specified by:
clearin interfaceList<E>- Overrides:
clearin classAbstractList<E>
-
poll
-
offer
-
peek
-
get
-
isEmpty
public boolean isEmpty()- Specified by:
isEmptyin interfaceCollection<E>- Specified by:
isEmptyin interfaceList<E>- Overrides:
isEmptyin classAbstractCollection<E>
-
size
public int size()- Specified by:
sizein interfaceCollection<E>- Specified by:
sizein interfaceList<E>- Specified by:
sizein classAbstractCollection<E>
-
toString
- Overrides:
toStringin classAbstractCollection<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
-
set
-
add
-
remove
-
remove
-
element
-