1 |
|
/* |
2 |
|
* Written by Doug Lea and Josh Bloch with assistance from members of |
3 |
|
* JCP JSR-166 Expert Group and released to the public domain, as explained |
4 |
< |
* at http://creativecommons.org/licenses/publicdomain |
4 |
> |
* at http://creativecommons.org/publicdomain/zero/1.0/ |
5 |
|
*/ |
6 |
|
|
7 |
|
package java.util; |
153 |
|
* <tt>Object</tt>. |
154 |
|
* |
155 |
|
* <p>This interface is a member of the <a |
156 |
< |
* href="{@docRoot}/../guide/collections/index.html"> Java Collections |
156 |
> |
* href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections |
157 |
|
* Framework</a>. |
158 |
|
* |
159 |
|
* @author Doug Lea |
161 |
|
* @since 1.6 |
162 |
|
* @param <E> the type of elements held in this collection |
163 |
|
*/ |
164 |
– |
|
164 |
|
public interface Deque<E> extends Queue<E> { |
165 |
|
/** |
166 |
|
* Inserts the specified element at the front of this deque if it is |
171 |
|
* @param e the element to add |
172 |
|
* @throws IllegalStateException if the element cannot be added at this |
173 |
|
* time due to capacity restrictions |
175 |
– |
* @throws NullPointerException if the specified element is null and this |
176 |
– |
* deque does not permit null elements |
174 |
|
* @throws ClassCastException if the class of the specified element |
175 |
|
* prevents it from being added to this deque |
176 |
+ |
* @throws NullPointerException if the specified element is null and this |
177 |
+ |
* deque does not permit null elements |
178 |
|
* @throws IllegalArgumentException if some property of the specified |
179 |
|
* element prevents it from being added to this deque |
180 |
|
*/ |
181 |
|
void addFirst(E e); |
182 |
|
|
183 |
|
/** |
184 |
< |
* Inserts the specified element at the end of this deque if it is |
184 |
> |
* Inserts the specified element at the end of this deque if it is |
185 |
|
* possible to do so immediately without violating capacity restrictions. |
186 |
|
* When using a capacity-restricted deque, it is generally preferable to |
187 |
|
* use method {@link #offerLast}. |
188 |
|
* |
189 |
+ |
* <p>This method is equivalent to {@link #add}. |
190 |
+ |
* |
191 |
|
* @param e the element to add |
192 |
|
* @throws IllegalStateException if the element cannot be added at this |
193 |
|
* time due to capacity restrictions |
193 |
– |
* @throws NullPointerException if the specified element is null and this |
194 |
– |
* deque does not permit null elements |
194 |
|
* @throws ClassCastException if the class of the specified element |
195 |
|
* prevents it from being added to this deque |
196 |
+ |
* @throws NullPointerException if the specified element is null and this |
197 |
+ |
* deque does not permit null elements |
198 |
|
* @throws IllegalArgumentException if some property of the specified |
199 |
|
* element prevents it from being added to this deque |
200 |
|
*/ |
207 |
|
* which can fail to insert an element only by throwing an exception. |
208 |
|
* |
209 |
|
* @param e the element to add |
210 |
< |
* @return <tt>true</tt> if it was possible to insert the element, |
211 |
< |
* else <tt>false</tt> |
211 |
< |
* @throws NullPointerException if the specified element is null and this |
212 |
< |
* deque does not permit null elements |
210 |
> |
* @return <tt>true</tt> if the element was added to this deque, else |
211 |
> |
* <tt>false</tt> |
212 |
|
* @throws ClassCastException if the class of the specified element |
213 |
|
* prevents it from being added to this deque |
214 |
+ |
* @throws NullPointerException if the specified element is null and this |
215 |
+ |
* deque does not permit null elements |
216 |
|
* @throws IllegalArgumentException if some property of the specified |
217 |
|
* element prevents it from being added to this deque |
218 |
|
*/ |
225 |
|
* which can fail to insert an element only by throwing an exception. |
226 |
|
* |
227 |
|
* @param e the element to add |
228 |
< |
* @return <tt>true</tt> if it was possible to insert the element, |
229 |
< |
* else <tt>false</tt> |
229 |
< |
* @throws NullPointerException if the specified element is null and this |
230 |
< |
* deque does not permit null elements |
228 |
> |
* @return <tt>true</tt> if the element was added to this deque, else |
229 |
> |
* <tt>false</tt> |
230 |
|
* @throws ClassCastException if the class of the specified element |
231 |
|
* prevents it from being added to this deque |
232 |
+ |
* @throws NullPointerException if the specified element is null and this |
233 |
+ |
* deque does not permit null elements |
234 |
|
* @throws IllegalArgumentException if some property of the specified |
235 |
|
* element prevents it from being added to this deque |
236 |
|
*/ |
238 |
|
|
239 |
|
/** |
240 |
|
* Retrieves and removes the first element of this deque. This method |
241 |
< |
* differs from {@link #pollFirst} only in that it throws an exception |
242 |
< |
* if this deque is empty. |
241 |
> |
* differs from {@link #pollFirst pollFirst} only in that it throws an |
242 |
> |
* exception if this deque is empty. |
243 |
|
* |
244 |
|
* @return the head of this deque |
245 |
|
* @throws NoSuchElementException if this deque is empty |
248 |
|
|
249 |
|
/** |
250 |
|
* Retrieves and removes the last element of this deque. This method |
251 |
< |
* differs from {@link #pollLast} only in that it throws an exception if |
252 |
< |
* this deque is empty. |
251 |
> |
* differs from {@link #pollLast pollLast} only in that it throws an |
252 |
> |
* exception if this deque is empty. |
253 |
|
* |
254 |
|
* @return the tail of this deque |
255 |
|
* @throws NoSuchElementException if this deque is empty |
274 |
|
|
275 |
|
/** |
276 |
|
* Retrieves, but does not remove, the first element of this deque. |
277 |
< |
* This method differs from {@link #peekFirst} only in that it throws an |
278 |
< |
* exception if this deque is empty. |
277 |
> |
* |
278 |
> |
* This method differs from {@link #peekFirst peekFirst} only in that it |
279 |
> |
* throws an exception if this deque is empty. |
280 |
|
* |
281 |
|
* @return the head of this deque |
282 |
|
* @throws NoSuchElementException if this deque is empty |
285 |
|
|
286 |
|
/** |
287 |
|
* Retrieves, but does not remove, the last element of this deque. |
288 |
< |
* This method differs from {@link #peekLast} only in that it throws an |
289 |
< |
* exception if this deque is empty. |
288 |
> |
* This method differs from {@link #peekLast peekLast} only in that it |
289 |
> |
* throws an exception if this deque is empty. |
290 |
|
* |
291 |
|
* @return the tail of this deque |
292 |
|
* @throws NoSuchElementException if this deque is empty |
313 |
|
* Removes the first occurrence of the specified element from this deque. |
314 |
|
* If the deque does not contain the element, it is unchanged. |
315 |
|
* More formally, removes the first element <tt>e</tt> such that |
316 |
< |
* <tt>(o==null ? e==null : o.equals(e))</tt> (if such an element exists). |
317 |
< |
* Returns true if this deque contained the specified element (or |
318 |
< |
* equivalently, if this deque changed as a result of the call). |
316 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt> |
317 |
> |
* (if such an element exists). |
318 |
> |
* Returns <tt>true</tt> if this deque contained the specified element |
319 |
> |
* (or equivalently, if this deque changed as a result of the call). |
320 |
|
* |
321 |
|
* @param o element to be removed from this deque, if present |
322 |
|
* @return <tt>true</tt> if an element was removed as a result of this call |
323 |
+ |
* @throws ClassCastException if the class of the specified element |
324 |
+ |
* is incompatible with this deque (optional) |
325 |
|
* @throws NullPointerException if the specified element is null and this |
326 |
|
* deque does not permit null elements (optional) |
322 |
– |
* @throws ClassCastException if the class of the specified element |
323 |
– |
* is incompatible with this collection (optional) |
327 |
|
*/ |
328 |
|
boolean removeFirstOccurrence(Object o); |
329 |
|
|
331 |
|
* Removes the last occurrence of the specified element from this deque. |
332 |
|
* If the deque does not contain the element, it is unchanged. |
333 |
|
* More formally, removes the last element <tt>e</tt> such that |
334 |
< |
* <tt>(o==null ? e==null : o.equals(e))</tt> (if such an element exists). |
335 |
< |
* Returns true if this deque contained the specified element (or |
336 |
< |
* equivalently, if this deque changed as a result of the call). |
334 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt> |
335 |
> |
* (if such an element exists). |
336 |
> |
* Returns <tt>true</tt> if this deque contained the specified element |
337 |
> |
* (or equivalently, if this deque changed as a result of the call). |
338 |
|
* |
339 |
|
* @param o element to be removed from this deque, if present |
340 |
|
* @return <tt>true</tt> if an element was removed as a result of this call |
341 |
+ |
* @throws ClassCastException if the class of the specified element |
342 |
+ |
* is incompatible with this deque (optional) |
343 |
|
* @throws NullPointerException if the specified element is null and this |
344 |
|
* deque does not permit null elements (optional) |
339 |
– |
* @throws ClassCastException if the class of the specified element |
340 |
– |
* is incompatible with this collection (optional) |
345 |
|
*/ |
346 |
|
boolean removeLastOccurrence(Object o); |
347 |
|
|
356 |
|
* When using a capacity-restricted deque, it is generally preferable to |
357 |
|
* use {@link #offer(Object) offer}. |
358 |
|
* |
359 |
< |
* <p>This method is equivalent to {@link #addLast(Object) addLast}. |
359 |
> |
* <p>This method is equivalent to {@link #addLast}. |
360 |
|
* |
361 |
|
* @param e the element to add |
362 |
< |
* @return <tt>true</tt> (as per the spec for {@link Collection#add}) |
362 |
> |
* @return <tt>true</tt> (as specified by {@link Collection#add}) |
363 |
|
* @throws IllegalStateException if the element cannot be added at this |
364 |
|
* time due to capacity restrictions |
361 |
– |
* @throws NullPointerException if the specified element is null and this |
362 |
– |
* deque does not permit null elements |
365 |
|
* @throws ClassCastException if the class of the specified element |
366 |
|
* prevents it from being added to this deque |
367 |
+ |
* @throws NullPointerException if the specified element is null and this |
368 |
+ |
* deque does not permit null elements |
369 |
|
* @throws IllegalArgumentException if some property of the specified |
370 |
|
* element prevents it from being added to this deque |
371 |
|
*/ |
385 |
|
* @param e the element to add |
386 |
|
* @return <tt>true</tt> if the element was added to this deque, else |
387 |
|
* <tt>false</tt> |
384 |
– |
* @throws NullPointerException if the specified element is null and this |
385 |
– |
* deque does not permit null elements |
388 |
|
* @throws ClassCastException if the class of the specified element |
389 |
|
* prevents it from being added to this deque |
390 |
+ |
* @throws NullPointerException if the specified element is null and this |
391 |
+ |
* deque does not permit null elements |
392 |
|
* @throws IllegalArgumentException if some property of the specified |
393 |
|
* element prevents it from being added to this deque |
394 |
|
*/ |
397 |
|
/** |
398 |
|
* Retrieves and removes the head of the queue represented by this deque |
399 |
|
* (in other words, the first element of this deque). |
400 |
< |
* This method differs from {@link #poll} only in that it throws an |
400 |
> |
* This method differs from {@link #poll poll} only in that it throws an |
401 |
|
* exception if this deque is empty. |
402 |
|
* |
403 |
|
* <p>This method is equivalent to {@link #removeFirst()}. |
422 |
|
/** |
423 |
|
* Retrieves, but does not remove, the head of the queue represented by |
424 |
|
* this deque (in other words, the first element of this deque). |
425 |
< |
* This method differs from {@link #peek} only in that it throws an |
425 |
> |
* This method differs from {@link #peek peek} only in that it throws an |
426 |
|
* exception if this deque is empty. |
427 |
|
* |
428 |
|
* <p>This method is equivalent to {@link #getFirst()}. |
459 |
|
* @param e the element to push |
460 |
|
* @throws IllegalStateException if the element cannot be added at this |
461 |
|
* time due to capacity restrictions |
458 |
– |
* @throws NullPointerException if the specified element is null and this |
459 |
– |
* deque does not permit null elements |
462 |
|
* @throws ClassCastException if the class of the specified element |
463 |
|
* prevents it from being added to this deque |
464 |
+ |
* @throws NullPointerException if the specified element is null and this |
465 |
+ |
* deque does not permit null elements |
466 |
|
* @throws IllegalArgumentException if some property of the specified |
467 |
|
* element prevents it from being added to this deque |
468 |
|
*/ |
487 |
|
* Removes the first occurrence of the specified element from this deque. |
488 |
|
* If the deque does not contain the element, it is unchanged. |
489 |
|
* More formally, removes the first element <tt>e</tt> such that |
490 |
< |
* <tt>(o==null ? e==null : o.equals(e))</tt> (if such an element exists). |
491 |
< |
* Returns true if this deque contained the specified element (or |
492 |
< |
* equivalently, if this deque changed as a result of the call). |
490 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt> |
491 |
> |
* (if such an element exists). |
492 |
> |
* Returns <tt>true</tt> if this deque contained the specified element |
493 |
> |
* (or equivalently, if this deque changed as a result of the call). |
494 |
|
* |
495 |
|
* <p>This method is equivalent to {@link #removeFirstOccurrence}. |
496 |
|
* |
497 |
|
* @param o element to be removed from this deque, if present |
498 |
|
* @return <tt>true</tt> if an element was removed as a result of this call |
499 |
+ |
* @throws ClassCastException if the class of the specified element |
500 |
+ |
* is incompatible with this deque (optional) |
501 |
|
* @throws NullPointerException if the specified element is null and this |
502 |
|
* deque does not permit null elements (optional) |
496 |
– |
* @throws ClassCastException if the class of the specified element |
497 |
– |
* is incompatible with this collection (optional) |
503 |
|
*/ |
504 |
|
boolean remove(Object o); |
505 |
|
|
506 |
|
/** |
507 |
|
* Returns <tt>true</tt> if this deque contains the specified element. |
508 |
< |
* More formally, returns <tt>true</tt> if and only if this deque |
509 |
< |
* contains at least one element <tt>e</tt> such that <tt>(o==null ? |
510 |
< |
* e==null : o.equals(e))</tt>. |
508 |
> |
* More formally, returns <tt>true</tt> if and only if this deque contains |
509 |
> |
* at least one element <tt>e</tt> such that |
510 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt>. |
511 |
|
* |
512 |
|
* @param o element whose presence in this deque is to be tested |
513 |
|
* @return <tt>true</tt> if this deque contains the specified element |
526 |
|
public int size(); |
527 |
|
|
528 |
|
/** |
529 |
< |
* Returns an iterator over the elements in this deque. The elements |
530 |
< |
* will be ordered from first (head) to last (tail). |
529 |
> |
* Returns an iterator over the elements in this deque in proper sequence. |
530 |
> |
* The elements will be returned in order from first (head) to last (tail). |
531 |
|
* |
532 |
< |
* @return an <tt>Iterator</tt> over the elements in this deque |
532 |
> |
* @return an iterator over the elements in this deque in proper sequence |
533 |
|
*/ |
534 |
|
Iterator<E> iterator(); |
535 |
+ |
|
536 |
+ |
/** |
537 |
+ |
* Returns an iterator over the elements in this deque in reverse |
538 |
+ |
* sequential order. The elements will be returned in order from |
539 |
+ |
* last (tail) to first (head). |
540 |
+ |
* |
541 |
+ |
* @return an iterator over the elements in this deque in reverse |
542 |
+ |
* sequence |
543 |
+ |
*/ |
544 |
+ |
Iterator<E> descendingIterator(); |
545 |
+ |
|
546 |
|
} |