24 |
|
* <tt>Deque</tt> implementations; in most implementations, insert |
25 |
|
* operations cannot fail. |
26 |
|
* |
27 |
< |
* <p>The twelve methods described above are summarized in the |
27 |
> |
* <p>The twelve methods described above are summarized in the |
28 |
|
* following table:<p> |
29 |
< |
* |
29 |
> |
* |
30 |
|
* <table BORDER CELLPADDING=3 CELLSPACING=1> |
31 |
|
* <tr> |
32 |
|
* <td></td> |
103 |
|
* |
104 |
|
* <p>Deques can also be used as LIFO (Last-In-First-Out) stacks. This |
105 |
|
* interface should be used in preference to the legacy {@link Stack} class. |
106 |
< |
* When a dequeue is used as a stack, elements are pushed and popped from the |
106 |
> |
* When a deque is used as a stack, elements are pushed and popped from the |
107 |
|
* beginning of the deque. Stack methods are precisely equivalent to |
108 |
|
* <tt>Deque</tt> methods as indicated in the table below:<p> |
109 |
|
* |
144 |
|
* take advantage of the ability to insert nulls. This is so because |
145 |
|
* <tt>null</tt> is used as a special return value by various methods |
146 |
|
* to indicated that the deque is empty. |
147 |
< |
* |
147 |
> |
* |
148 |
|
* <p><tt>Deque</tt> implementations generally do not define |
149 |
|
* element-based versions of the <tt>equals</tt> and <tt>hashCode</tt> |
150 |
|
* methods, but instead inherit the identity-based versions from class |
162 |
|
|
163 |
|
public interface Deque<E> extends Queue<E> { |
164 |
|
/** |
165 |
< |
* Inserts the specified element to the front this deque unless it would |
165 |
> |
* Inserts the specified element at the front of this deque unless it would |
166 |
|
* violate capacity restrictions. When using a capacity-restricted deque, |
167 |
|
* this method is generally preferable to method <tt>addFirst</tt>, which |
168 |
|
* can fail to insert an element only by throwing an exception. |
170 |
|
* @param e the element to insert |
171 |
|
* @return <tt>true</tt> if it was possible to insert the element, |
172 |
|
* else <tt>false</tt> |
173 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
173 |
> |
* @throws NullPointerException if the specified element is null and this |
174 |
|
* deque does not permit null elements |
175 |
|
*/ |
176 |
|
boolean offerFirst(E e); |
184 |
|
* @param e the element to insert |
185 |
|
* @return <tt>true</tt> if it was possible to insert the element, |
186 |
|
* else <tt>false</tt> |
187 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
187 |
> |
* @throws NullPointerException if the specified element is null and this |
188 |
|
* deque does not permit null elements |
189 |
|
*/ |
190 |
|
boolean offerLast(E e); |
191 |
|
|
192 |
|
/** |
193 |
< |
* Inserts the specified element to the front of this deque unless it |
193 |
> |
* Inserts the specified element at the front of this deque unless it |
194 |
|
* would violate capacity restrictions. |
195 |
|
* |
196 |
|
* @param e the element to insert |
197 |
|
* @throws IllegalStateException if it was not possible to insert |
198 |
|
* the element due to capacity restrictions |
199 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
199 |
> |
* @throws NullPointerException if the specified element is null and this |
200 |
|
* deque does not permit null elements |
201 |
|
*/ |
202 |
|
void addFirst(E e); |
208 |
|
* @param e the element to insert |
209 |
|
* @throws IllegalStateException if it was not possible to insert |
210 |
|
* the element due to capacity restrictions |
211 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
211 |
> |
* @throws NullPointerException if the specified element is null and this |
212 |
|
* deque does not permit null elements |
213 |
|
*/ |
214 |
|
void addLast(E e); |
271 |
|
|
272 |
|
/** |
273 |
|
* Retrieves, but does not remove, the first element of this |
274 |
< |
* deque. This method differs from the <tt>peek</tt> method only |
274 |
> |
* deque. This method differs from the <tt>peekFirst</tt> method only |
275 |
|
* in that it throws an exception if this deque is empty. |
276 |
|
* |
277 |
|
* @return the first element of this deque |
281 |
|
|
282 |
|
/** |
283 |
|
* Retrieves, but does not remove, the last element of this |
284 |
< |
* deque. This method differs from the <tt>peek</tt> method only |
284 |
> |
* deque. This method differs from the <tt>peekLast</tt> method only |
285 |
|
* in that it throws an exception if this deque is empty. |
286 |
|
* |
287 |
|
* @return the last element of this deque |
296 |
|
* such that <tt>(o==null ? e==null : o.equals(e))</tt> (if |
297 |
|
* such an element exists). |
298 |
|
* |
299 |
< |
* @param e element to be removed from this deque, if present |
299 |
> |
* @param o element to be removed from this deque, if present |
300 |
|
* @return <tt>true</tt> if the deque contained the specified element |
301 |
|
* @throws NullPointerException if the specified element is <tt>null</tt> |
302 |
|
*/ |
303 |
< |
boolean removeFirstOccurrence(Object e); |
303 |
> |
boolean removeFirstOccurrence(Object o); |
304 |
|
|
305 |
|
/** |
306 |
|
* Removes the last occurrence of the specified element in this |
309 |
|
* such that <tt>(o==null ? e==null : o.equals(e))</tt> (if |
310 |
|
* such an element exists). |
311 |
|
* |
312 |
< |
* @param e element to be removed from this deque, if present |
312 |
> |
* @param o element to be removed from this deque, if present |
313 |
|
* @return <tt>true</tt> if the deque contained the specified element |
314 |
|
* @throws NullPointerException if the specified element is <tt>null</tt> |
315 |
|
*/ |
316 |
< |
boolean removeLastOccurrence(Object e); |
316 |
> |
boolean removeLastOccurrence(Object o); |
317 |
|
|
318 |
|
|
319 |
|
// *** Queue methods *** |
331 |
|
* @param e the element to insert |
332 |
|
* @return <tt>true</tt> if it was possible to insert the element, |
333 |
|
* else <tt>false</tt> |
334 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
334 |
> |
* @throws NullPointerException if the specified element is null and this |
335 |
|
* deque does not permit null elements |
336 |
|
*/ |
337 |
|
boolean offer(E e); |
339 |
|
/** |
340 |
|
* Inserts the specified element into the queue represented by this |
341 |
|
* deque unless it would violate capacity restrictions. In other words, |
342 |
< |
* inserts the specified element as the last element of this deque. |
342 |
> |
* inserts the specified element as the last element of this deque. |
343 |
|
* |
344 |
|
* <p>This method is equivalent to {@link #addLast}. |
345 |
|
* |
347 |
|
* @return <tt>true</tt> (as per the spec for {@link Collection#add}) |
348 |
|
* @throws IllegalStateException if it was not possible to insert |
349 |
|
* the element due to capacity restrictions |
350 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
350 |
> |
* @throws NullPointerException if the specified element is null and this |
351 |
|
* deque does not permit null elements |
352 |
|
*/ |
353 |
|
boolean add(E e); |
381 |
|
* Retrieves, but does not remove, the head of the queue represented by |
382 |
|
* this deque, returning <tt>null</tt> if this deque is empty. |
383 |
|
* |
384 |
< |
* <p>This method is equivalent to {@link #peekFirst()} |
384 |
> |
* <p>This method is equivalent to {@link #peekFirst()}. |
385 |
|
* |
386 |
|
* @return the head of the queue represented by this deque, or |
387 |
|
* <tt>null</tt> if this deque is empty |
393 |
|
* this deque. This method differs from the <tt>peek</tt> method only in |
394 |
|
* that it throws an exception if this deque is empty. |
395 |
|
* |
396 |
< |
* <p>This method is equivalent to {@link #getFirst()} |
396 |
> |
* <p>This method is equivalent to {@link #getFirst()}. |
397 |
|
* |
398 |
|
* @return the head of the queue represented by this deque |
399 |
|
* @throws NoSuchElementException if this deque is empty |
405 |
|
|
406 |
|
/** |
407 |
|
* Pushes an element onto the stack represented by this deque. In other |
408 |
< |
* words, inserts the element to the front this deque unless it would |
408 |
> |
* words, inserts the element at the front of this deque unless it would |
409 |
|
* violate capacity restrictions. |
410 |
|
* |
411 |
|
* <p>This method is equivalent to {@link #addFirst}. |
412 |
|
* |
413 |
+ |
* @param e the element to push |
414 |
|
* @throws IllegalStateException if it was not possible to insert |
415 |
|
* the element due to capacity restrictions |
416 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
416 |
> |
* @throws NullPointerException if the specified element is null and this |
417 |
|
* deque does not permit null elements |
418 |
|
*/ |
419 |
|
void push(E e); |
436 |
|
/** |
437 |
|
* Returns an iterator over the elements in this deque. The elements |
438 |
|
* will be ordered from first (head) to last (tail). |
439 |
< |
* |
439 |
> |
* |
440 |
|
* @return an <tt>Iterator</tt> over the elements in this deque |
441 |
|
*/ |
442 |
|
Iterator<E> iterator(); |