1 *java.util.concurrent.LinkedBlockingDeque* *LinkedBlockingDeque* An optionally-b
3 public class LinkedBlockingDeque<E>
4 extends |java.util.AbstractQueue|
5 implements |java.util.concurrent.BlockingDeque|
8 |java.util.concurrent.LinkedBlockingDeque_Description|
9 |java.util.concurrent.LinkedBlockingDeque_Fields|
10 |java.util.concurrent.LinkedBlockingDeque_Constructors|
11 |java.util.concurrent.LinkedBlockingDeque_Methods|
13 ================================================================================
15 *java.util.concurrent.LinkedBlockingDeque_Constructors*
16 |java.util.concurrent.LinkedBlockingDeque()|Creates a LinkedBlockingDeque with
17 |java.util.concurrent.LinkedBlockingDeque(Collection<?extendsE>)|Creates a Link
18 |java.util.concurrent.LinkedBlockingDeque(int)|Creates a LinkedBlockingDeque wi
20 *java.util.concurrent.LinkedBlockingDeque_Methods*
21 |java.util.concurrent.LinkedBlockingDeque.add(E)|Inserts the specified element
22 |java.util.concurrent.LinkedBlockingDeque.addFirst(E)|
23 |java.util.concurrent.LinkedBlockingDeque.addLast(E)|
24 |java.util.concurrent.LinkedBlockingDeque.clear()|Atomically removes all of the
25 |java.util.concurrent.LinkedBlockingDeque.contains(Object)|Returns true if this
26 |java.util.concurrent.LinkedBlockingDeque.descendingIterator()|Returns an itera
27 |java.util.concurrent.LinkedBlockingDeque.drainTo(Collection<?superE>)|
28 |java.util.concurrent.LinkedBlockingDeque.drainTo(Collection<?superE>,int)|
29 |java.util.concurrent.LinkedBlockingDeque.element()|Retrieves, but does not rem
30 |java.util.concurrent.LinkedBlockingDeque.getFirst()|
31 |java.util.concurrent.LinkedBlockingDeque.getLast()|
32 |java.util.concurrent.LinkedBlockingDeque.iterator()|Returns an iterator over t
33 |java.util.concurrent.LinkedBlockingDeque.offer(E)|
34 |java.util.concurrent.LinkedBlockingDeque.offer(E,long,TimeUnit)|
35 |java.util.concurrent.LinkedBlockingDeque.offerFirst(E)|
36 |java.util.concurrent.LinkedBlockingDeque.offerFirst(E,long,TimeUnit)|
37 |java.util.concurrent.LinkedBlockingDeque.offerLast(E)|
38 |java.util.concurrent.LinkedBlockingDeque.offerLast(E,long,TimeUnit)|
39 |java.util.concurrent.LinkedBlockingDeque.peek()|
40 |java.util.concurrent.LinkedBlockingDeque.peekFirst()|
41 |java.util.concurrent.LinkedBlockingDeque.peekLast()|
42 |java.util.concurrent.LinkedBlockingDeque.poll()|
43 |java.util.concurrent.LinkedBlockingDeque.poll(long,TimeUnit)|
44 |java.util.concurrent.LinkedBlockingDeque.pollFirst()|
45 |java.util.concurrent.LinkedBlockingDeque.pollFirst(long,TimeUnit)|
46 |java.util.concurrent.LinkedBlockingDeque.pollLast()|
47 |java.util.concurrent.LinkedBlockingDeque.pollLast(long,TimeUnit)|
48 |java.util.concurrent.LinkedBlockingDeque.pop()|
49 |java.util.concurrent.LinkedBlockingDeque.push(E)|
50 |java.util.concurrent.LinkedBlockingDeque.put(E)|
51 |java.util.concurrent.LinkedBlockingDeque.putFirst(E)|
52 |java.util.concurrent.LinkedBlockingDeque.putLast(E)|
53 |java.util.concurrent.LinkedBlockingDeque.remainingCapacity()|Returns the numbe
54 |java.util.concurrent.LinkedBlockingDeque.remove()|Retrieves and removes the he
55 |java.util.concurrent.LinkedBlockingDeque.remove(Object)|Removes the first occu
56 |java.util.concurrent.LinkedBlockingDeque.removeFirst()|
57 |java.util.concurrent.LinkedBlockingDeque.removeFirstOccurrence(Object)|
58 |java.util.concurrent.LinkedBlockingDeque.removeLast()|
59 |java.util.concurrent.LinkedBlockingDeque.removeLastOccurrence(Object)|
60 |java.util.concurrent.LinkedBlockingDeque.size()|Returns the number of elements
61 |java.util.concurrent.LinkedBlockingDeque.take()|
62 |java.util.concurrent.LinkedBlockingDeque.takeFirst()|
63 |java.util.concurrent.LinkedBlockingDeque.takeLast()|
64 |java.util.concurrent.LinkedBlockingDeque.toArray()|Returns an array containing
65 |java.util.concurrent.LinkedBlockingDeque.toArray(T[])|Returns an array contain
66 |java.util.concurrent.LinkedBlockingDeque.toString()|
68 *java.util.concurrent.LinkedBlockingDeque_Description*
70 An optionally-bounded blocking deque(|java.util.concurrent.BlockingDeque|)
71 based on linked nodes.
73 The optional capacity bound constructor argument serves as a way to prevent
74 excessive expansion. The capacity, if unspecified, is equal to
75 (|java.lang.Integer|) . Linked nodes are dynamically created upon each
76 insertion unless this would bring the deque above capacity.
78 Most operations run in constant time (ignoring time spent blocking). Exceptions
79 include remove(|java.util.concurrent.LinkedBlockingDeque|) ,
80 removeFirstOccurrence(|java.util.concurrent.LinkedBlockingDeque|) ,
81 removeLastOccurrence(|java.util.concurrent.LinkedBlockingDeque|) ,
82 contains(|java.util.concurrent.LinkedBlockingDeque|) ,
83 iterator.remove()(|java.util.concurrent.LinkedBlockingDeque|) , and the bulk
84 operations, all of which run in linear time.
86 This class and its iterator implement all of the optional methods of the
87 (|java.util.Collection|) and (|java.util.Iterator|) interfaces.
89 This class is a member of the <a
90 href="/../technotes/guides/collections/index.html"> Java Collections Framework.
94 *java.util.concurrent.LinkedBlockingDeque()*
96 public LinkedBlockingDeque()
98 Creates a LinkedBlockingDeque with a capacity of (|java.lang.Integer|) .
101 *java.util.concurrent.LinkedBlockingDeque(Collection<?extendsE>)*
103 public LinkedBlockingDeque(java.util.Collection<? extends E> c)
105 Creates a LinkedBlockingDeque with a capacity of (|java.lang.Integer|) ,
106 initially containing the elements of the given collection, added in traversal
107 order of the collection's iterator.
109 c - the collection of elements to initially contain
111 *java.util.concurrent.LinkedBlockingDeque(int)*
113 public LinkedBlockingDeque(int capacity)
115 Creates a LinkedBlockingDeque with the given (fixed) capacity.
117 capacity - the capacity of this deque
119 *java.util.concurrent.LinkedBlockingDeque.add(E)*
121 public boolean add(E e)
123 Inserts the specified element at the end of this deque unless it would violate
124 capacity restrictions. When using a capacity-restricted deque, it is generally
125 preferable to use method offer(|java.util.concurrent.LinkedBlockingDeque|) .
127 This method is equivalent to (|java.util.concurrent.LinkedBlockingDeque|) .
131 *java.util.concurrent.LinkedBlockingDeque.addFirst(E)*
133 public void addFirst(E e)
139 *java.util.concurrent.LinkedBlockingDeque.addLast(E)*
141 public void addLast(E e)
147 *java.util.concurrent.LinkedBlockingDeque.clear()*
151 Atomically removes all of the elements from this deque. The deque will be empty
152 after this call returns.
156 *java.util.concurrent.LinkedBlockingDeque.contains(Object)*
158 public boolean contains(java.lang.Object o)
160 Returns true if this deque contains the specified element. More formally,
161 returns true if and only if this deque contains at least one element e such
165 o - object to be checked for containment in this deque
167 Returns: true if this deque contains the specified element
169 *java.util.concurrent.LinkedBlockingDeque.descendingIterator()*
171 public |java.util.Iterator|<E> descendingIterator()
173 Returns an iterator over the elements in this deque in reverse sequential
174 order. The elements will be returned in order from last (tail) to first (head).
175 The returned Iterator is a "weakly consistent" iterator that will never throw
176 (|java.util.ConcurrentModificationException|) , and guarantees to traverse
177 elements as they existed upon construction of the iterator, and may (but is not
178 guaranteed to) reflect any modifications subsequent to construction.
182 *java.util.concurrent.LinkedBlockingDeque.drainTo(Collection<?superE>)*
184 public int drainTo(java.util.Collection<? super E> c)
190 *java.util.concurrent.LinkedBlockingDeque.drainTo(Collection<?superE>,int)*
193 java.util.Collection<? super E> c,
200 *java.util.concurrent.LinkedBlockingDeque.element()*
204 Retrieves, but does not remove, the head of the queue represented by this
205 deque. This method differs from
206 peek(|java.util.concurrent.LinkedBlockingDeque|) only in that it throws an
207 exception if this deque is empty.
209 This method is equivalent to
210 getFirst(|java.util.concurrent.LinkedBlockingDeque|) .
214 Returns: the head of the queue represented by this deque
216 *java.util.concurrent.LinkedBlockingDeque.getFirst()*
218 public |E| getFirst()
224 *java.util.concurrent.LinkedBlockingDeque.getLast()*
232 *java.util.concurrent.LinkedBlockingDeque.iterator()*
234 public |java.util.Iterator|<E> iterator()
236 Returns an iterator over the elements in this deque in proper sequence. The
237 elements will be returned in order from first (head) to last (tail). The
238 returned Iterator is a "weakly consistent" iterator that will never throw
239 (|java.util.ConcurrentModificationException|) , and guarantees to traverse
240 elements as they existed upon construction of the iterator, and may (but is not
241 guaranteed to) reflect any modifications subsequent to construction.
245 Returns: an iterator over the elements in this deque in proper sequence
247 *java.util.concurrent.LinkedBlockingDeque.offer(E)*
249 public boolean offer(E e)
255 *java.util.concurrent.LinkedBlockingDeque.offer(E,long,TimeUnit)*
257 public boolean offer(
260 java.util.concurrent.TimeUnit unit)
261 throws |java.lang.InterruptedException|
267 *java.util.concurrent.LinkedBlockingDeque.offerFirst(E)*
269 public boolean offerFirst(E e)
275 *java.util.concurrent.LinkedBlockingDeque.offerFirst(E,long,TimeUnit)*
277 public boolean offerFirst(
280 java.util.concurrent.TimeUnit unit)
281 throws |java.lang.InterruptedException|
287 *java.util.concurrent.LinkedBlockingDeque.offerLast(E)*
289 public boolean offerLast(E e)
295 *java.util.concurrent.LinkedBlockingDeque.offerLast(E,long,TimeUnit)*
297 public boolean offerLast(
300 java.util.concurrent.TimeUnit unit)
301 throws |java.lang.InterruptedException|
307 *java.util.concurrent.LinkedBlockingDeque.peek()*
315 *java.util.concurrent.LinkedBlockingDeque.peekFirst()*
317 public |E| peekFirst()
323 *java.util.concurrent.LinkedBlockingDeque.peekLast()*
325 public |E| peekLast()
331 *java.util.concurrent.LinkedBlockingDeque.poll()*
339 *java.util.concurrent.LinkedBlockingDeque.poll(long,TimeUnit)*
343 java.util.concurrent.TimeUnit unit)
344 throws |java.lang.InterruptedException|
350 *java.util.concurrent.LinkedBlockingDeque.pollFirst()*
352 public |E| pollFirst()
358 *java.util.concurrent.LinkedBlockingDeque.pollFirst(long,TimeUnit)*
360 public |E| pollFirst(
362 java.util.concurrent.TimeUnit unit)
363 throws |java.lang.InterruptedException|
369 *java.util.concurrent.LinkedBlockingDeque.pollLast()*
371 public |E| pollLast()
377 *java.util.concurrent.LinkedBlockingDeque.pollLast(long,TimeUnit)*
381 java.util.concurrent.TimeUnit unit)
382 throws |java.lang.InterruptedException|
388 *java.util.concurrent.LinkedBlockingDeque.pop()*
396 *java.util.concurrent.LinkedBlockingDeque.push(E)*
398 public void push(E e)
404 *java.util.concurrent.LinkedBlockingDeque.put(E)*
407 throws |java.lang.InterruptedException|
413 *java.util.concurrent.LinkedBlockingDeque.putFirst(E)*
415 public void putFirst(E e)
416 throws |java.lang.InterruptedException|
422 *java.util.concurrent.LinkedBlockingDeque.putLast(E)*
424 public void putLast(E e)
425 throws |java.lang.InterruptedException|
431 *java.util.concurrent.LinkedBlockingDeque.remainingCapacity()*
433 public int remainingCapacity()
435 Returns the number of additional elements that this deque can ideally (in the
436 absence of memory or resource constraints) accept without blocking. This is
437 always equal to the initial capacity of this deque less the current size of
440 Note that you cannot always tell if an attempt to insert an element will
441 succeed by inspecting remainingCapacity because it may be the case that another
442 thread is about to insert or remove an element.
446 *java.util.concurrent.LinkedBlockingDeque.remove()*
450 Retrieves and removes the head of the queue represented by this deque. This
451 method differs from poll(|java.util.concurrent.LinkedBlockingDeque|) only in
452 that it throws an exception if this deque is empty.
454 This method is equivalent to
455 removeFirst(|java.util.concurrent.LinkedBlockingDeque|) .
459 Returns: the head of the queue represented by this deque
461 *java.util.concurrent.LinkedBlockingDeque.remove(Object)*
463 public boolean remove(java.lang.Object o)
465 Removes the first occurrence of the specified element from this deque. If the
466 deque does not contain the element, it is unchanged. More formally, removes the
467 first element e such that o.equals(e) (if such an element exists). Returns true
468 if this deque contained the specified element (or equivalently, if this deque
469 changed as a result of the call).
471 This method is equivalent to
472 removeFirstOccurrence(|java.util.concurrent.LinkedBlockingDeque|) .
475 o - element to be removed from this deque, if present
477 Returns: true if this deque changed as a result of the call
479 *java.util.concurrent.LinkedBlockingDeque.removeFirst()*
481 public |E| removeFirst()
487 *java.util.concurrent.LinkedBlockingDeque.removeFirstOccurrence(Object)*
489 public boolean removeFirstOccurrence(java.lang.Object o)
495 *java.util.concurrent.LinkedBlockingDeque.removeLast()*
497 public |E| removeLast()
503 *java.util.concurrent.LinkedBlockingDeque.removeLastOccurrence(Object)*
505 public boolean removeLastOccurrence(java.lang.Object o)
511 *java.util.concurrent.LinkedBlockingDeque.size()*
515 Returns the number of elements in this deque.
519 Returns: the number of elements in this deque
521 *java.util.concurrent.LinkedBlockingDeque.take()*
524 throws |java.lang.InterruptedException|
530 *java.util.concurrent.LinkedBlockingDeque.takeFirst()*
532 public |E| takeFirst()
533 throws |java.lang.InterruptedException|
539 *java.util.concurrent.LinkedBlockingDeque.takeLast()*
541 public |E| takeLast()
542 throws |java.lang.InterruptedException|
548 *java.util.concurrent.LinkedBlockingDeque.toArray()*
550 public |java.lang.Object|[] toArray()
552 Returns an array containing all of the elements in this deque, in proper
553 sequence (from first to last element).
555 The returned array will be "safe" in that no references to it are maintained by
556 this deque. (In other words, this method must allocate a new array). The caller
557 is thus free to modify the returned array.
559 This method acts as bridge between array-based and collection-based APIs.
563 Returns: an array containing all of the elements in this deque
565 *java.util.concurrent.LinkedBlockingDeque.toArray(T[])*
567 public |T|[] toArray(T[] a)
569 Returns an array containing all of the elements in this deque, in proper
570 sequence; the runtime type of the returned array is that of the specified
571 array. If the deque fits in the specified array, it is returned therein.
572 Otherwise, a new array is allocated with the runtime type of the specified
573 array and the size of this deque.
575 If this deque fits in the specified array with room to spare (i.e., the array
576 has more elements than this deque), the element in the array immediately
577 following the end of the deque is set to null.
579 Like the (|java.util.concurrent.LinkedBlockingDeque|) method, this method acts
580 as bridge between array-based and collection-based APIs. Further, this method
581 allows precise control over the runtime type of the output array, and may,
582 under certain circumstances, be used to save allocation costs.
584 Suppose x is a deque known to contain only strings. The following code can be
585 used to dump the deque into a newly allocated array of String:
589 String[] y = x.toArray(new String[0]);
591 Note that toArray(new Object[0]) is identical in function to toArray().
594 a - the array into which the elements of the deque are to be stored, if it is big
595 enough; otherwise, a new array of the same runtime type is allocated for
598 Returns: an array containing all of the elements in this deque
600 *java.util.concurrent.LinkedBlockingDeque.toString()*
602 public |java.lang.String| toString()