|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.common.collect.Queues
public final class Queues
Static utility methods pertaining to Queue
and Deque
instances.
Also see this class's counterparts Lists
, Sets
, and Maps
.
Method Summary | ||
---|---|---|
static
|
drain(java.util.concurrent.BlockingQueue<E> q,
java.util.Collection<? super E> buffer,
int numElements,
long timeout,
java.util.concurrent.TimeUnit unit)
Drains the queue as BlockingQueue.drainTo(Collection, int) , but if the requested
numElements elements are not available, it will wait for them up to the specified
timeout. |
|
static
|
drainUninterruptibly(java.util.concurrent.BlockingQueue<E> q,
java.util.Collection<? super E> buffer,
int numElements,
long timeout,
java.util.concurrent.TimeUnit unit)
Drains the queue as drain(BlockingQueue, Collection, int, long, TimeUnit), but with a different behavior in case it is interrupted while waiting. |
|
static
|
newArrayBlockingQueue(int capacity)
Creates an empty ArrayBlockingQueue instance. |
|
static
|
newArrayDeque()
Creates an empty ArrayDeque instance. |
|
static
|
newArrayDeque(java.lang.Iterable<? extends E> elements)
Creates an ArrayDeque instance containing the given elements. |
|
static
|
newConcurrentLinkedQueue()
Creates an empty ConcurrentLinkedQueue instance. |
|
static
|
newConcurrentLinkedQueue(java.lang.Iterable<? extends E> elements)
Creates an ConcurrentLinkedQueue instance containing the given elements. |
|
static
|
newLinkedBlockingDeque()
Creates an empty LinkedBlockingDeque instance. |
|
static
|
newLinkedBlockingDeque(int capacity)
Creates a LinkedBlockingDeque with the given (fixed) capacity. |
|
static
|
newLinkedBlockingDeque(java.lang.Iterable<? extends E> elements)
Creates an LinkedBlockingDeque instance containing the given elements. |
|
static
|
newLinkedBlockingQueue()
Creates an empty LinkedBlockingQueue instance. |
|
static
|
newLinkedBlockingQueue(int capacity)
Creates a LinkedBlockingQueue with the given (fixed) capacity. |
|
static
|
newLinkedBlockingQueue(java.lang.Iterable<? extends E> elements)
Creates an LinkedBlockingQueue instance containing the given elements. |
|
static
|
newPriorityBlockingQueue()
Creates an empty PriorityBlockingQueue instance. |
|
static
|
newPriorityBlockingQueue(java.lang.Iterable<? extends E> elements)
Creates an PriorityBlockingQueue instance containing the given elements. |
|
static
|
newPriorityQueue()
Creates an empty PriorityQueue instance. |
|
static
|
newPriorityQueue(java.lang.Iterable<? extends E> elements)
Creates an PriorityQueue instance containing the given elements. |
|
static
|
newSynchronousQueue()
Creates an empty SynchronousQueue instance. |
|
static
|
synchronizedQueue(java.util.Queue<E> queue)
Returns a synchronized (thread-safe) queue backed by the specified queue. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity)
ArrayBlockingQueue
instance.
ArrayBlockingQueue
public static <E> java.util.ArrayDeque<E> newArrayDeque()
ArrayDeque
instance.
ArrayDeque
public static <E> java.util.ArrayDeque<E> newArrayDeque(java.lang.Iterable<? extends E> elements)
ArrayDeque
instance containing the given elements.
elements
- the elements that the queue should contain, in order
ArrayDeque
containing those elementspublic static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue()
ConcurrentLinkedQueue
instance.
ConcurrentLinkedQueue
public static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue(java.lang.Iterable<? extends E> elements)
ConcurrentLinkedQueue
instance containing the given elements.
elements
- the elements that the queue should contain, in order
ConcurrentLinkedQueue
containing those elementspublic static <E> java.util.concurrent.LinkedBlockingDeque<E> newLinkedBlockingDeque()
LinkedBlockingDeque
instance.
LinkedBlockingDeque
public static <E> java.util.concurrent.LinkedBlockingDeque<E> newLinkedBlockingDeque(int capacity)
LinkedBlockingDeque
with the given (fixed) capacity.
capacity
- the capacity of this deque
LinkedBlockingDeque
java.lang.IllegalArgumentException
- if capacity
is less than 1public static <E> java.util.concurrent.LinkedBlockingDeque<E> newLinkedBlockingDeque(java.lang.Iterable<? extends E> elements)
LinkedBlockingDeque
instance containing the given elements.
elements
- the elements that the queue should contain, in order
LinkedBlockingDeque
containing those elementspublic static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue()
LinkedBlockingQueue
instance.
LinkedBlockingQueue
public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue(int capacity)
LinkedBlockingQueue
with the given (fixed) capacity.
capacity
- the capacity of this queue
LinkedBlockingQueue
java.lang.IllegalArgumentException
- if capacity
is less than 1public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue(java.lang.Iterable<? extends E> elements)
LinkedBlockingQueue
instance containing the given elements.
elements
- the elements that the queue should contain, in order
LinkedBlockingQueue
containing those elementspublic static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue()
PriorityBlockingQueue
instance.
PriorityBlockingQueue
public static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue(java.lang.Iterable<? extends E> elements)
PriorityBlockingQueue
instance containing the given elements.
elements
- the elements that the queue should contain, in order
PriorityBlockingQueue
containing those elementspublic static <E> java.util.PriorityQueue<E> newPriorityQueue()
PriorityQueue
instance.
PriorityQueue
public static <E> java.util.PriorityQueue<E> newPriorityQueue(java.lang.Iterable<? extends E> elements)
PriorityQueue
instance containing the given elements.
elements
- the elements that the queue should contain, in order
PriorityQueue
containing those elementspublic static <E> java.util.concurrent.SynchronousQueue<E> newSynchronousQueue()
SynchronousQueue
instance.
SynchronousQueue
@Beta public static <E> int drain(java.util.concurrent.BlockingQueue<E> q, java.util.Collection<? super E> buffer, int numElements, long timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
BlockingQueue.drainTo(Collection, int)
, but if the requested
numElements
elements are not available, it will wait for them up to the specified
timeout.
q
- the blocking queue to be drainedbuffer
- where to add the transferred elementsnumElements
- the number of elements to be waited fortimeout
- how long to wait before giving up, in units of unit
unit
- a TimeUnit
determining how to interpret the timeout parameter
java.lang.InterruptedException
- if interrupted while waiting@Beta public static <E> int drainUninterruptibly(java.util.concurrent.BlockingQueue<E> q, java.util.Collection<? super E> buffer, int numElements, long timeout, java.util.concurrent.TimeUnit unit)
InterruptedException
is thrown).
q
- the blocking queue to be drainedbuffer
- where to add the transferred elementsnumElements
- the number of elements to be waited fortimeout
- how long to wait before giving up, in units of unit
unit
- a TimeUnit
determining how to interpret the timeout parameter
@Beta public static <E> java.util.Queue<E> synchronizedQueue(java.util.Queue<E> queue)
It is imperative that the user manually synchronize on the returned queue when accessing the queue's iterator:
Queue<E> queue = Queues.synchronizedQueue(MinMaxPriorityQueue<E>.create());
...
queue.add(element); // Needn't be in synchronized block
...
synchronized (queue) { // Must synchronize on queue!
Iterator<E> i = queue.iterator(); // Must be in synchronized block
while (i.hasNext()) {
foo(i.next());
}
}
Failure to follow this advice may result in non-deterministic behavior.
The returned queue will be serializable if the specified queue is serializable.
queue
- the queue to be wrapped in a synchronized view
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |