Package org.eclipse.jetty.util
Class ArrayQueue<E>
- java.lang.Object
-
- java.util.AbstractCollection<E>
-
- java.util.AbstractList<E>
-
- org.eclipse.jetty.util.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 Summary
Fields Modifier and Type Field Description protected Object[]
_elements
protected int
_growCapacity
protected Object
_lock
protected int
_nextE
protected int
_nextSlot
protected int
_size
static int
DEFAULT_CAPACITY
static int
DEFAULT_GROWTH
-
Fields inherited from class java.util.AbstractList
modCount
-
-
Constructor Summary
Constructors Constructor Description ArrayQueue()
ArrayQueue(int capacity)
ArrayQueue(int initCapacity, int growBy)
ArrayQueue(int initCapacity, int growBy, Object lock)
ArrayQueue(Object lock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(int index, E element)
boolean
add(E e)
void
addUnsafe(E e)
Add without synchronization or bounds checkingvoid
clear()
protected E
dequeue()
E
element()
protected boolean
enqueue(E e)
E
get(int index)
int
getCapacity()
int
getNextSlotUnsafe()
E
getUnsafe(int index)
Get without synchronization or bounds checking.protected boolean
growUnsafe()
boolean
isEmpty()
Object
lock()
boolean
offer(E e)
E
peek()
E
peekUnsafe()
E
poll()
E
pollUnsafe()
E
remove()
E
remove(int index)
protected void
resizeUnsafe(int newCapacity)
E
set(int index, E element)
int
size()
int
sizeUnsafe()
-
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, toString
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
-
Methods inherited from interface java.util.List
addAll, contains, containsAll, remove, removeAll, replaceAll, retainAll, sort, spliterator, toArray, toArray
-
-
-
-
Field Detail
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITY
- See Also:
- Constant Field Values
-
DEFAULT_GROWTH
public static final int DEFAULT_GROWTH
- See Also:
- Constant Field Values
-
_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
-
-
Method Detail
-
lock
public Object lock()
-
getCapacity
public int getCapacity()
-
getNextSlotUnsafe
public int getNextSlotUnsafe()
- Returns:
- the next slot to be used
-
add
public boolean add(E 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)
-
peekUnsafe
public E peekUnsafe()
-
pollUnsafe
public E pollUnsafe()
-
dequeue
protected E dequeue()
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<E>
- Specified by:
clear
in interfaceList<E>
- Overrides:
clear
in classAbstractList<E>
-
isEmpty
public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<E>
- Specified by:
isEmpty
in interfaceList<E>
- Overrides:
isEmpty
in classAbstractCollection<E>
-
size
public int size()
- Specified by:
size
in interfaceCollection<E>
- Specified by:
size
in interfaceList<E>
- Specified by:
size
in classAbstractCollection<E>
-
sizeUnsafe
public int sizeUnsafe()
-
get
public E get(int index)
-
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)
-
remove
public E remove(int index)
-
add
public void add(int index, E element)
-
resizeUnsafe
protected void resizeUnsafe(int newCapacity)
-
growUnsafe
protected boolean growUnsafe()
-
-