ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/BlockingDeque.java
Revision: 1.34
Committed: Sat May 6 06:55:50 2017 UTC (7 years ago) by jsr166
Branch: MAIN
Changes since 1.33: +15 -15 lines
Log Message:
8179367: update use of align, valign attributes in java.base to use style attribute

File Contents

# User Rev Content
1 dl 1.1 /*
2     * Written by Doug Lea with assistance from members of JCP JSR-166
3     * Expert Group and released to the public domain, as explained at
4 jsr166 1.21 * http://creativecommons.org/publicdomain/zero/1.0/
5 dl 1.1 */
6    
7     package java.util.concurrent;
8 jsr166 1.29
9     import java.util.Deque;
10     import java.util.Iterator;
11     import java.util.NoSuchElementException;
12 dl 1.1
13     /**
14 jsr166 1.10 * A {@link Deque} that additionally supports blocking operations that wait
15     * for the deque to become non-empty when retrieving an element, and wait for
16     * space to become available in the deque when storing an element.
17     *
18 jsr166 1.24 * <p>{@code BlockingDeque} methods come in four forms, with different ways
19 jsr166 1.10 * of handling operations that cannot be satisfied immediately, but may be
20     * satisfied at some point in the future:
21     * one throws an exception, the second returns a special value (either
22 jsr166 1.24 * {@code null} or {@code false}, depending on the operation), the third
23 jsr166 1.10 * blocks the current thread indefinitely until the operation can succeed,
24     * and the fourth blocks for only a given maximum time limit before giving
25     * up. These methods are summarized in the following table:
26 dl 1.1 *
27     * <table BORDER CELLPADDING=3 CELLSPACING=1>
28 jsr166 1.25 * <caption>Summary of BlockingDeque methods</caption>
29 dl 1.1 * <tr>
30 jsr166 1.34 * <td style="text-align:center" COLSPAN = 5> <b>First Element (Head)</b></td>
31 dl 1.1 * </tr>
32     * <tr>
33     * <td></td>
34 jsr166 1.34 * <td style="text-align:center"><em>Throws exception</em></td>
35     * <td style="text-align:center"><em>Special value</em></td>
36     * <td style="text-align:center"><em>Blocks</em></td>
37     * <td style="text-align:center"><em>Times out</em></td>
38 dl 1.1 * </tr>
39     * <tr>
40     * <td><b>Insert</b></td>
41 jsr166 1.32 * <td>{@link #addFirst(Object) addFirst(e)}</td>
42 jsr166 1.10 * <td>{@link #offerFirst(Object) offerFirst(e)}</td>
43 jsr166 1.32 * <td>{@link #putFirst(Object) putFirst(e)}</td>
44 dl 1.1 * <td>{@link #offerFirst(Object, long, TimeUnit) offerFirst(e, time, unit)}</td>
45 jsr166 1.10 * </tr>
46     * <tr>
47     * <td><b>Remove</b></td>
48 jsr166 1.32 * <td>{@link #removeFirst() removeFirst()}</td>
49     * <td>{@link #pollFirst() pollFirst()}</td>
50     * <td>{@link #takeFirst() takeFirst()}</td>
51 jsr166 1.10 * <td>{@link #pollFirst(long, TimeUnit) pollFirst(time, unit)}</td>
52     * </tr>
53     * <tr>
54     * <td><b>Examine</b></td>
55 jsr166 1.32 * <td>{@link #getFirst() getFirst()}</td>
56     * <td>{@link #peekFirst() peekFirst()}</td>
57 jsr166 1.10 * <td><em>not applicable</em></td>
58     * <td><em>not applicable</em></td>
59     * </tr>
60     * <tr>
61 jsr166 1.34 * <td style="text-align:center" COLSPAN = 5> <b>Last Element (Tail)</b></td>
62 jsr166 1.10 * </tr>
63     * <tr>
64     * <td></td>
65 jsr166 1.34 * <td style="text-align:center"><em>Throws exception</em></td>
66     * <td style="text-align:center"><em>Special value</em></td>
67     * <td style="text-align:center"><em>Blocks</em></td>
68     * <td style="text-align:center"><em>Times out</em></td>
69 jsr166 1.10 * </tr>
70     * <tr>
71     * <td><b>Insert</b></td>
72 jsr166 1.32 * <td>{@link #addLast(Object) addLast(e)}</td>
73 jsr166 1.10 * <td>{@link #offerLast(Object) offerLast(e)}</td>
74 jsr166 1.32 * <td>{@link #putLast(Object) putLast(e)}</td>
75 jsr166 1.4 * <td>{@link #offerLast(Object, long, TimeUnit) offerLast(e, time, unit)}</td>
76 dl 1.1 * </tr>
77     * <tr>
78     * <td><b>Remove</b></td>
79 jsr166 1.10 * <td>{@link #removeLast() removeLast()}</td>
80     * <td>{@link #pollLast() pollLast()}</td>
81 jsr166 1.32 * <td>{@link #takeLast() takeLast()}</td>
82 dl 1.1 * <td>{@link #pollLast(long, TimeUnit) pollLast(time, unit)}</td>
83     * </tr>
84 jsr166 1.10 * <tr>
85     * <td><b>Examine</b></td>
86 jsr166 1.32 * <td>{@link #getLast() getLast()}</td>
87     * <td>{@link #peekLast() peekLast()}</td>
88 jsr166 1.10 * <td><em>not applicable</em></td>
89     * <td><em>not applicable</em></td>
90     * </tr>
91 dl 1.1 * </table>
92     *
93 jsr166 1.24 * <p>Like any {@link BlockingQueue}, a {@code BlockingDeque} is thread safe,
94 jsr166 1.10 * does not permit null elements, and may (or may not) be
95     * capacity-constrained.
96     *
97 jsr166 1.24 * <p>A {@code BlockingDeque} implementation may be used directly as a FIFO
98     * {@code BlockingQueue}. The methods inherited from the
99     * {@code BlockingQueue} interface are precisely equivalent to
100     * {@code BlockingDeque} methods as indicated in the following table:
101 dl 1.1 *
102     * <table BORDER CELLPADDING=3 CELLSPACING=1>
103 jsr166 1.25 * <caption>Comparison of BlockingQueue and BlockingDeque methods</caption>
104 dl 1.1 * <tr>
105 jsr166 1.34 * <td style="text-align:center"> <b>{@code BlockingQueue} Method</b></td>
106     * <td style="text-align:center"> <b>Equivalent {@code BlockingDeque} Method</b></td>
107 dl 1.1 * </tr>
108     * <tr>
109 jsr166 1.34 * <td style="text-align:center" COLSPAN = 2> <b>Insert</b></td>
110 jsr166 1.10 * </tr>
111     * <tr>
112     * <td>{@link #add(Object) add(e)}</td>
113     * <td>{@link #addLast(Object) addLast(e)}</td>
114     * </tr>
115     * <tr>
116     * <td>{@link #offer(Object) offer(e)}</td>
117     * <td>{@link #offerLast(Object) offerLast(e)}</td>
118     * </tr>
119     * <tr>
120     * <td>{@link #put(Object) put(e)}</td>
121     * <td>{@link #putLast(Object) putLast(e)}</td>
122     * </tr>
123     * <tr>
124     * <td>{@link #offer(Object, long, TimeUnit) offer(e, time, unit)}</td>
125 dl 1.1 * <td>{@link #offerLast(Object, long, TimeUnit) offerLast(e, time, unit)}</td>
126 jsr166 1.10 * </tr>
127     * <tr>
128 jsr166 1.34 * <td style="text-align:center" COLSPAN = 2> <b>Remove</b></td>
129 jsr166 1.10 * </tr>
130     * <tr>
131     * <td>{@link #remove() remove()}</td>
132     * <td>{@link #removeFirst() removeFirst()}</td>
133     * </tr>
134     * <tr>
135     * <td>{@link #poll() poll()}</td>
136     * <td>{@link #pollFirst() pollFirst()}</td>
137     * </tr>
138     * <tr>
139     * <td>{@link #take() take()}</td>
140     * <td>{@link #takeFirst() takeFirst()}</td>
141     * </tr>
142     * <tr>
143     * <td>{@link #poll(long, TimeUnit) poll(time, unit)}</td>
144 dl 1.1 * <td>{@link #pollFirst(long, TimeUnit) pollFirst(time, unit)}</td>
145 jsr166 1.10 * </tr>
146     * <tr>
147 jsr166 1.34 * <td style="text-align:center" COLSPAN = 2> <b>Examine</b></td>
148 jsr166 1.10 * </tr>
149     * <tr>
150     * <td>{@link #element() element()}</td>
151     * <td>{@link #getFirst() getFirst()}</td>
152     * </tr>
153     * <tr>
154     * <td>{@link #peek() peek()}</td>
155     * <td>{@link #peekFirst() peekFirst()}</td>
156     * </tr>
157 dl 1.1 * </table>
158     *
159 jsr166 1.18 * <p>Memory consistency effects: As with other concurrent
160     * collections, actions in a thread prior to placing an object into a
161     * {@code BlockingDeque}
162     * <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
163     * actions subsequent to the access or removal of that element from
164     * the {@code BlockingDeque} in another thread.
165     *
166 dl 1.1 * <p>This interface is a member of the
167 jsr166 1.33 * <a href="{@docRoot}/java/util/package-summary.html#CollectionsFramework">
168 dl 1.1 * Java Collections Framework</a>.
169     *
170     * @since 1.6
171     * @author Doug Lea
172 jsr166 1.28 * @param <E> the type of elements held in this deque
173 dl 1.1 */
174 jsr166 1.10 public interface BlockingDeque<E> extends BlockingQueue<E>, Deque<E> {
175     /*
176     * We have "diamond" multiple interface inheritance here, and that
177     * introduces ambiguities. Methods might end up with different
178     * specs depending on the branch chosen by javadoc. Thus a lot of
179     * methods specs here are copied from superinterfaces.
180     */
181    
182     /**
183     * Inserts the specified element at the front of this deque if it is
184     * possible to do so immediately without violating capacity restrictions,
185 jsr166 1.24 * throwing an {@code IllegalStateException} if no space is currently
186 jsr166 1.10 * available. When using a capacity-restricted deque, it is generally
187     * preferable to use {@link #offerFirst(Object) offerFirst}.
188     *
189 jsr166 1.12 * @param e the element to add
190 jsr166 1.10 * @throws IllegalStateException {@inheritDoc}
191     * @throws ClassCastException {@inheritDoc}
192     * @throws NullPointerException if the specified element is null
193     * @throws IllegalArgumentException {@inheritDoc}
194     */
195     void addFirst(E e);
196    
197     /**
198     * Inserts the specified element at the end of this deque if it is
199     * possible to do so immediately without violating capacity restrictions,
200 jsr166 1.24 * throwing an {@code IllegalStateException} if no space is currently
201 jsr166 1.10 * available. When using a capacity-restricted deque, it is generally
202     * preferable to use {@link #offerLast(Object) offerLast}.
203     *
204 jsr166 1.12 * @param e the element to add
205 jsr166 1.10 * @throws IllegalStateException {@inheritDoc}
206     * @throws ClassCastException {@inheritDoc}
207     * @throws NullPointerException if the specified element is null
208     * @throws IllegalArgumentException {@inheritDoc}
209     */
210     void addLast(E e);
211    
212     /**
213     * Inserts the specified element at the front of this deque if it is
214 jsr166 1.12 * possible to do so immediately without violating capacity restrictions,
215 jsr166 1.24 * returning {@code true} upon success and {@code false} if no space is
216 jsr166 1.12 * currently available.
217 jsr166 1.10 * When using a capacity-restricted deque, this method is generally
218     * preferable to the {@link #addFirst(Object) addFirst} method, which can
219     * fail to insert an element only by throwing an exception.
220     *
221 jsr166 1.12 * @param e the element to add
222 jsr166 1.10 * @throws ClassCastException {@inheritDoc}
223     * @throws NullPointerException if the specified element is null
224     * @throws IllegalArgumentException {@inheritDoc}
225     */
226     boolean offerFirst(E e);
227    
228     /**
229     * Inserts the specified element at the end of this deque if it is
230 jsr166 1.12 * possible to do so immediately without violating capacity restrictions,
231 jsr166 1.24 * returning {@code true} upon success and {@code false} if no space is
232 jsr166 1.12 * currently available.
233 jsr166 1.10 * When using a capacity-restricted deque, this method is generally
234     * preferable to the {@link #addLast(Object) addLast} method, which can
235     * fail to insert an element only by throwing an exception.
236     *
237 jsr166 1.12 * @param e the element to add
238 jsr166 1.10 * @throws ClassCastException {@inheritDoc}
239     * @throws NullPointerException if the specified element is null
240     * @throws IllegalArgumentException {@inheritDoc}
241     */
242     boolean offerLast(E e);
243 dl 1.1
244     /**
245 jsr166 1.12 * Inserts the specified element at the front of this deque,
246 dl 1.1 * waiting if necessary for space to become available.
247 jsr166 1.10 *
248 jsr166 1.7 * @param e the element to add
249 jsr166 1.10 * @throws InterruptedException if interrupted while waiting
250     * @throws ClassCastException if the class of the specified element
251     * prevents it from being added to this deque
252     * @throws NullPointerException if the specified element is null
253     * @throws IllegalArgumentException if some property of the specified
254     * element prevents it from being added to this deque
255 dl 1.1 */
256 jsr166 1.7 void putFirst(E e) throws InterruptedException;
257 dl 1.1
258     /**
259 jsr166 1.12 * Inserts the specified element at the end of this deque,
260 dl 1.1 * waiting if necessary for space to become available.
261 jsr166 1.10 *
262 jsr166 1.7 * @param e the element to add
263 jsr166 1.10 * @throws InterruptedException if interrupted while waiting
264     * @throws ClassCastException if the class of the specified element
265     * prevents it from being added to this deque
266     * @throws NullPointerException if the specified element is null
267     * @throws IllegalArgumentException if some property of the specified
268     * element prevents it from being added to this deque
269 dl 1.1 */
270 jsr166 1.7 void putLast(E e) throws InterruptedException;
271 dl 1.1
272     /**
273 jsr166 1.12 * Inserts the specified element at the front of this deque,
274 jsr166 1.10 * waiting up to the specified wait time if necessary for space to
275 dl 1.1 * become available.
276 jsr166 1.10 *
277 jsr166 1.7 * @param e the element to add
278 dl 1.1 * @param timeout how long to wait before giving up, in units of
279 jsr166 1.24 * {@code unit}
280     * @param unit a {@code TimeUnit} determining how to interpret the
281     * {@code timeout} parameter
282     * @return {@code true} if successful, or {@code false} if
283 jsr166 1.10 * the specified waiting time elapses before space is available
284     * @throws InterruptedException if interrupted while waiting
285     * @throws ClassCastException if the class of the specified element
286     * prevents it from being added to this deque
287     * @throws NullPointerException if the specified element is null
288     * @throws IllegalArgumentException if some property of the specified
289     * element prevents it from being added to this deque
290 dl 1.1 */
291 jsr166 1.7 boolean offerFirst(E e, long timeout, TimeUnit unit)
292 dl 1.1 throws InterruptedException;
293    
294     /**
295 jsr166 1.12 * Inserts the specified element at the end of this deque,
296 jsr166 1.10 * waiting up to the specified wait time if necessary for space to
297 dl 1.1 * become available.
298 jsr166 1.10 *
299 jsr166 1.7 * @param e the element to add
300 dl 1.1 * @param timeout how long to wait before giving up, in units of
301 jsr166 1.24 * {@code unit}
302     * @param unit a {@code TimeUnit} determining how to interpret the
303     * {@code timeout} parameter
304     * @return {@code true} if successful, or {@code false} if
305 jsr166 1.10 * the specified waiting time elapses before space is available
306     * @throws InterruptedException if interrupted while waiting
307     * @throws ClassCastException if the class of the specified element
308     * prevents it from being added to this deque
309     * @throws NullPointerException if the specified element is null
310     * @throws IllegalArgumentException if some property of the specified
311     * element prevents it from being added to this deque
312 dl 1.1 */
313 jsr166 1.7 boolean offerLast(E e, long timeout, TimeUnit unit)
314 dl 1.1 throws InterruptedException;
315    
316 jsr166 1.10 /**
317     * Retrieves and removes the first element of this deque, waiting
318     * if necessary until an element becomes available.
319     *
320     * @return the head of this deque
321     * @throws InterruptedException if interrupted while waiting
322     */
323     E takeFirst() throws InterruptedException;
324    
325     /**
326     * Retrieves and removes the last element of this deque, waiting
327     * if necessary until an element becomes available.
328     *
329     * @return the tail of this deque
330     * @throws InterruptedException if interrupted while waiting
331     */
332     E takeLast() throws InterruptedException;
333 dl 1.1
334     /**
335     * Retrieves and removes the first element of this deque, waiting
336 jsr166 1.10 * up to the specified wait time if necessary for an element to
337     * become available.
338     *
339 dl 1.1 * @param timeout how long to wait before giving up, in units of
340 jsr166 1.24 * {@code unit}
341     * @param unit a {@code TimeUnit} determining how to interpret the
342     * {@code timeout} parameter
343     * @return the head of this deque, or {@code null} if the specified
344 jsr166 1.10 * waiting time elapses before an element is available
345     * @throws InterruptedException if interrupted while waiting
346 dl 1.1 */
347     E pollFirst(long timeout, TimeUnit unit)
348     throws InterruptedException;
349    
350     /**
351     * Retrieves and removes the last element of this deque, waiting
352 jsr166 1.10 * up to the specified wait time if necessary for an element to
353     * become available.
354     *
355 dl 1.1 * @param timeout how long to wait before giving up, in units of
356 jsr166 1.24 * {@code unit}
357     * @param unit a {@code TimeUnit} determining how to interpret the
358     * {@code timeout} parameter
359     * @return the tail of this deque, or {@code null} if the specified
360 jsr166 1.10 * waiting time elapses before an element is available
361     * @throws InterruptedException if interrupted while waiting
362 dl 1.1 */
363     E pollLast(long timeout, TimeUnit unit)
364     throws InterruptedException;
365    
366     /**
367 jsr166 1.10 * Removes the first occurrence of the specified element from this deque.
368     * If the deque does not contain the element, it is unchanged.
369 jsr166 1.24 * More formally, removes the first element {@code e} such that
370     * {@code o.equals(e)} (if such an element exists).
371     * Returns {@code true} if this deque contained the specified element
372 jsr166 1.12 * (or equivalently, if this deque changed as a result of the call).
373 jsr166 1.10 *
374     * @param o element to be removed from this deque, if present
375 jsr166 1.24 * @return {@code true} if an element was removed as a result of this call
376 jsr166 1.10 * @throws ClassCastException if the class of the specified element
377 dl 1.22 * is incompatible with this deque
378 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
379 dl 1.22 * @throws NullPointerException if the specified element is null
380 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
381 jsr166 1.10 */
382     boolean removeFirstOccurrence(Object o);
383    
384     /**
385     * Removes the last occurrence of the specified element from this deque.
386     * If the deque does not contain the element, it is unchanged.
387 jsr166 1.24 * More formally, removes the last element {@code e} such that
388     * {@code o.equals(e)} (if such an element exists).
389     * Returns {@code true} if this deque contained the specified element
390 jsr166 1.12 * (or equivalently, if this deque changed as a result of the call).
391 jsr166 1.10 *
392     * @param o element to be removed from this deque, if present
393 jsr166 1.24 * @return {@code true} if an element was removed as a result of this call
394 jsr166 1.10 * @throws ClassCastException if the class of the specified element
395 dl 1.22 * is incompatible with this deque
396 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
397 dl 1.22 * @throws NullPointerException if the specified element is null
398 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
399 jsr166 1.10 */
400     boolean removeLastOccurrence(Object o);
401    
402     // *** BlockingQueue methods ***
403    
404     /**
405     * Inserts the specified element into the queue represented by this deque
406     * (in other words, at the tail of this deque) if it is possible to do so
407     * immediately without violating capacity restrictions, returning
408 jsr166 1.24 * {@code true} upon success and throwing an
409     * {@code IllegalStateException} if no space is currently available.
410 jsr166 1.10 * When using a capacity-restricted deque, it is generally preferable to
411     * use {@link #offer(Object) offer}.
412     *
413     * <p>This method is equivalent to {@link #addLast(Object) addLast}.
414     *
415     * @param e the element to add
416     * @throws IllegalStateException {@inheritDoc}
417     * @throws ClassCastException if the class of the specified element
418     * prevents it from being added to this deque
419     * @throws NullPointerException if the specified element is null
420     * @throws IllegalArgumentException if some property of the specified
421     * element prevents it from being added to this deque
422     */
423     boolean add(E e);
424    
425     /**
426     * Inserts the specified element into the queue represented by this deque
427     * (in other words, at the tail of this deque) if it is possible to do so
428     * immediately without violating capacity restrictions, returning
429 jsr166 1.24 * {@code true} upon success and {@code false} if no space is currently
430 jsr166 1.10 * available. When using a capacity-restricted deque, this method is
431     * generally preferable to the {@link #add} method, which can fail to
432     * insert an element only by throwing an exception.
433     *
434     * <p>This method is equivalent to {@link #offerLast(Object) offerLast}.
435     *
436     * @param e the element to add
437     * @throws ClassCastException if the class of the specified element
438     * prevents it from being added to this deque
439     * @throws NullPointerException if the specified element is null
440     * @throws IllegalArgumentException if some property of the specified
441     * element prevents it from being added to this deque
442     */
443     boolean offer(E e);
444    
445     /**
446     * Inserts the specified element into the queue represented by this deque
447     * (in other words, at the tail of this deque), waiting if necessary for
448     * space to become available.
449 jsr166 1.6 *
450 jsr166 1.10 * <p>This method is equivalent to {@link #putLast(Object) putLast}.
451 jsr166 1.6 *
452 jsr166 1.8 * @param e the element to add
453 jsr166 1.10 * @throws InterruptedException {@inheritDoc}
454     * @throws ClassCastException if the class of the specified element
455     * prevents it from being added to this deque
456     * @throws NullPointerException if the specified element is null
457     * @throws IllegalArgumentException if some property of the specified
458     * element prevents it from being added to this deque
459 dl 1.1 */
460 jsr166 1.8 void put(E e) throws InterruptedException;
461 dl 1.1
462 jsr166 1.4 /**
463 jsr166 1.10 * Inserts the specified element into the queue represented by this deque
464     * (in other words, at the tail of this deque), waiting up to the
465     * specified wait time if necessary for space to become available.
466 jsr166 1.6 *
467 jsr166 1.10 * <p>This method is equivalent to
468 jsr166 1.13 * {@link #offerLast(Object,long,TimeUnit) offerLast}.
469 dl 1.1 *
470 jsr166 1.10 * @param e the element to add
471 jsr166 1.24 * @return {@code true} if the element was added to this deque, else
472     * {@code false}
473 jsr166 1.10 * @throws InterruptedException {@inheritDoc}
474     * @throws ClassCastException if the class of the specified element
475     * prevents it from being added to this deque
476     * @throws NullPointerException if the specified element is null
477     * @throws IllegalArgumentException if some property of the specified
478     * element prevents it from being added to this deque
479 dl 1.1 */
480 jsr166 1.8 boolean offer(E e, long timeout, TimeUnit unit)
481 dl 1.1 throws InterruptedException;
482    
483     /**
484 jsr166 1.10 * Retrieves and removes the head of the queue represented by this deque
485     * (in other words, the first element of this deque).
486 jsr166 1.32 * This method differs from {@link #poll() poll()} only in that it
487 jsr166 1.14 * throws an exception if this deque is empty.
488 jsr166 1.10 *
489     * <p>This method is equivalent to {@link #removeFirst() removeFirst}.
490     *
491     * @return the head of the queue represented by this deque
492     * @throws NoSuchElementException if this deque is empty
493     */
494     E remove();
495    
496     /**
497     * Retrieves and removes the head of the queue represented by this deque
498     * (in other words, the first element of this deque), or returns
499 jsr166 1.24 * {@code null} if this deque is empty.
500 jsr166 1.10 *
501     * <p>This method is equivalent to {@link #pollFirst()}.
502     *
503 jsr166 1.24 * @return the head of this deque, or {@code null} if this deque is empty
504 jsr166 1.10 */
505     E poll();
506    
507     /**
508     * Retrieves and removes the head of the queue represented by this deque
509     * (in other words, the first element of this deque), waiting if
510     * necessary until an element becomes available.
511 jsr166 1.6 *
512 jsr166 1.10 * <p>This method is equivalent to {@link #takeFirst() takeFirst}.
513 jsr166 1.6 *
514 dl 1.1 * @return the head of this deque
515 jsr166 1.10 * @throws InterruptedException if interrupted while waiting
516 dl 1.1 */
517     E take() throws InterruptedException;
518    
519     /**
520 jsr166 1.10 * Retrieves and removes the head of the queue represented by this deque
521     * (in other words, the first element of this deque), waiting up to the
522     * specified wait time if necessary for an element to become available.
523 jsr166 1.6 *
524 jsr166 1.10 * <p>This method is equivalent to
525     * {@link #pollFirst(long,TimeUnit) pollFirst}.
526 jsr166 1.6 *
527 jsr166 1.24 * @return the head of this deque, or {@code null} if the
528 jsr166 1.10 * specified waiting time elapses before an element is available
529     * @throws InterruptedException if interrupted while waiting
530 dl 1.1 */
531     E poll(long timeout, TimeUnit unit)
532     throws InterruptedException;
533 jsr166 1.10
534     /**
535     * Retrieves, but does not remove, the head of the queue represented by
536     * this deque (in other words, the first element of this deque).
537 jsr166 1.32 * This method differs from {@link #peek() peek} only in that it throws an
538 jsr166 1.10 * exception if this deque is empty.
539     *
540     * <p>This method is equivalent to {@link #getFirst() getFirst}.
541     *
542     * @return the head of this deque
543     * @throws NoSuchElementException if this deque is empty
544     */
545     E element();
546    
547     /**
548     * Retrieves, but does not remove, the head of the queue represented by
549     * this deque (in other words, the first element of this deque), or
550 jsr166 1.24 * returns {@code null} if this deque is empty.
551 jsr166 1.10 *
552     * <p>This method is equivalent to {@link #peekFirst() peekFirst}.
553     *
554 jsr166 1.24 * @return the head of this deque, or {@code null} if this deque is empty
555 jsr166 1.10 */
556     E peek();
557    
558     /**
559     * Removes the first occurrence of the specified element from this deque.
560     * If the deque does not contain the element, it is unchanged.
561 jsr166 1.24 * More formally, removes the first element {@code e} such that
562     * {@code o.equals(e)} (if such an element exists).
563     * Returns {@code true} if this deque contained the specified element
564 jsr166 1.12 * (or equivalently, if this deque changed as a result of the call).
565 jsr166 1.10 *
566     * <p>This method is equivalent to
567     * {@link #removeFirstOccurrence(Object) removeFirstOccurrence}.
568     *
569     * @param o element to be removed from this deque, if present
570 jsr166 1.24 * @return {@code true} if this deque changed as a result of the call
571 jsr166 1.10 * @throws ClassCastException if the class of the specified element
572 dl 1.22 * is incompatible with this deque
573 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
574 dl 1.22 * @throws NullPointerException if the specified element is null
575 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
576 jsr166 1.10 */
577     boolean remove(Object o);
578    
579     /**
580 jsr166 1.24 * Returns {@code true} if this deque contains the specified element.
581     * More formally, returns {@code true} if and only if this deque contains
582     * at least one element {@code e} such that {@code o.equals(e)}.
583 jsr166 1.10 *
584     * @param o object to be checked for containment in this deque
585 jsr166 1.24 * @return {@code true} if this deque contains the specified element
586 jsr166 1.10 * @throws ClassCastException if the class of the specified element
587 dl 1.22 * is incompatible with this deque
588 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
589 dl 1.22 * @throws NullPointerException if the specified element is null
590 jsr166 1.31 * (<a href="{@docRoot}/../api/java/util/Collection.html#optional-restrictions">optional</a>)
591 jsr166 1.10 */
592 jsr166 1.30 boolean contains(Object o);
593 jsr166 1.10
594     /**
595     * Returns the number of elements in this deque.
596     *
597     * @return the number of elements in this deque
598     */
599 jsr166 1.30 int size();
600 jsr166 1.10
601     /**
602 jsr166 1.11 * Returns an iterator over the elements in this deque in proper sequence.
603     * The elements will be returned in order from first (head) to last (tail).
604 jsr166 1.10 *
605 jsr166 1.11 * @return an iterator over the elements in this deque in proper sequence
606 jsr166 1.10 */
607     Iterator<E> iterator();
608    
609     // *** Stack methods ***
610    
611     /**
612 jsr166 1.26 * Pushes an element onto the stack represented by this deque (in other
613     * words, at the head of this deque) if it is possible to do so
614     * immediately without violating capacity restrictions, throwing an
615     * {@code IllegalStateException} if no space is currently available.
616 jsr166 1.10 *
617     * <p>This method is equivalent to {@link #addFirst(Object) addFirst}.
618     *
619     * @throws IllegalStateException {@inheritDoc}
620     * @throws ClassCastException {@inheritDoc}
621     * @throws NullPointerException if the specified element is null
622     * @throws IllegalArgumentException {@inheritDoc}
623     */
624     void push(E e);
625 dl 1.1 }