E
- The element typejava.lang.Iterable<E>
, java.util.Collection<E>
, java.util.concurrent.BlockingQueue<E>
, java.util.Queue<E>
public class BlockingArrayQueue<E>
extends java.util.AbstractList<E>
implements java.util.concurrent.BlockingQueue<E>
This queue is uses a variant of the two lock queue algorithm to provide an efficient queue or list backed by a growable circular array.
Unlike ArrayBlockingQueue
, this class is able to grow and provides a blocking put call.
The queue has both a capacity (the size of the array currently allocated) and a max capacity (the maximum size that may be allocated), which defaults to
Integer.MAX_VALUE
.
Modifier and Type | Field | Description |
---|---|---|
static int |
DEFAULT_CAPACITY |
Default initial capacity, 128.
|
static int |
DEFAULT_GROWTH |
Default growth factor, 64.
|
Constructor | Description |
---|---|
BlockingArrayQueue() |
Creates an unbounded
BlockingArrayQueue with default initial capacity and grow factor. |
BlockingArrayQueue(int maxCapacity) |
Creates a bounded
BlockingArrayQueue that does not grow. |
BlockingArrayQueue(int capacity,
int growBy) |
Creates an unbounded
BlockingArrayQueue that grows by the given parameter. |
BlockingArrayQueue(int capacity,
int growBy,
int maxCapacity) |
Create a bounded
BlockingArrayQueue that grows by the given parameter. |
Modifier and Type | Method | Description |
---|---|---|
void |
add(int index,
E e) |
|
boolean |
add(E e) |
|
void |
clear() |
|
int |
drainTo(java.util.Collection<? super E> c) |
|
int |
drainTo(java.util.Collection<? super E> c,
int maxElements) |
|
E |
element() |
|
E |
get(int index) |
|
int |
getCapacity() |
|
int |
getMaxCapacity() |
|
java.util.Iterator<E> |
iterator() |
|
java.util.ListIterator<E> |
listIterator(int index) |
|
boolean |
offer(E e) |
|
boolean |
offer(E o,
long timeout,
java.util.concurrent.TimeUnit unit) |
|
E |
peek() |
|
E |
poll() |
|
E |
poll(long time,
java.util.concurrent.TimeUnit unit) |
|
void |
put(E o) |
|
int |
remainingCapacity() |
|
E |
remove() |
|
E |
remove(int index) |
|
boolean |
remove(java.lang.Object o) |
|
E |
set(int index,
E e) |
|
int |
size() |
|
E |
take() |
addAll, contains, containsAll, isEmpty, removeAll, retainAll, toArray, toArray, toString
addAll, equals, hashCode, indexOf, lastIndexOf, listIterator, removeRange, subList
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, spliterator, stream, toArray, toArray
public static final int DEFAULT_CAPACITY
public static final int DEFAULT_GROWTH
public BlockingArrayQueue()
BlockingArrayQueue
with default initial capacity and grow factor.DEFAULT_CAPACITY
,
DEFAULT_GROWTH
public BlockingArrayQueue(int maxCapacity)
BlockingArrayQueue
that does not grow. The capacity of the queue is fixed and equal to the given parameter.maxCapacity
- the maximum capacitypublic BlockingArrayQueue(int capacity, int growBy)
BlockingArrayQueue
that grows by the given parameter.capacity
- the initial capacitygrowBy
- the growth factorpublic BlockingArrayQueue(int capacity, int growBy, int maxCapacity)
BlockingArrayQueue
that grows by the given parameter.capacity
- the initial capacitygrowBy
- the growth factormaxCapacity
- the maximum capacitypublic void clear()
public int size()
public java.util.Iterator<E> iterator()
public boolean offer(E e)
public boolean add(E e)
public void put(E o) throws java.lang.InterruptedException
put
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public boolean offer(E o, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
offer
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public E take() throws java.lang.InterruptedException
take
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public E poll(long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
poll
in interface java.util.concurrent.BlockingQueue<E>
java.lang.InterruptedException
public boolean remove(java.lang.Object o)
public int remainingCapacity()
remainingCapacity
in interface java.util.concurrent.BlockingQueue<E>
public int drainTo(java.util.Collection<? super E> c)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
public int drainTo(java.util.Collection<? super E> c, int maxElements)
drainTo
in interface java.util.concurrent.BlockingQueue<E>
public java.util.ListIterator<E> listIterator(int index)
listIterator
in class java.util.AbstractList<E>
public int getCapacity()
public int getMaxCapacity()
Copyright © 1995–2018 Webtide. All rights reserved.