ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/BlockingDeque.java
Revision: 1.37
Committed: Mon Oct 1 00:10:53 2018 UTC (5 years, 7 months ago) by jsr166
Branch: MAIN
CVS Tags: HEAD
Changes since 1.36: +9 -9 lines
Log Message:
update to using jdk11 by default, except link to jdk10 javadocs;
sync @docRoot references in javadoc with upstream

File Contents

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