ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/BlockingDeque.java
Revision: 1.26
Committed: Thu May 2 06:38:33 2013 UTC (11 years, 1 month ago) by jsr166
Branch: MAIN
Changes since 1.25: +4 -3 lines
Log Message:
fix up exception spec javadoc for deque methods

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