ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/BlockingDeque.java
Revision: 1.12
Committed: Tue May 17 16:20:40 2005 UTC (19 years ago) by jsr166
Branch: MAIN
Changes since 1.11: +20 -12 lines
Log Message:
doc fixes

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