24 |
|
* <tt>Deque</tt> implementations; in most implementations, insert |
25 |
|
* operations cannot fail. |
26 |
|
* |
27 |
< |
* <p>The twelve methods described above are are summarized in the |
28 |
< |
* follwoing table:<p> |
29 |
< |
* |
27 |
> |
* <p>The twelve methods described above are summarized in the |
28 |
> |
* following table:<p> |
29 |
> |
* |
30 |
|
* <table BORDER CELLPADDING=3 CELLSPACING=1> |
31 |
|
* <tr> |
32 |
|
* <td></td> |
65 |
|
* |
66 |
|
* <p>This interface extends the {@link Queue} interface. When a deque is |
67 |
|
* used as a queue, FIFO (First-In-First-Out) behavior results. Elements are |
68 |
< |
* added to the end of the deque and removed from the beginning. The methods |
68 |
> |
* added at the end of the deque and removed from the beginning. The methods |
69 |
|
* inherited from the <tt>Queue</tt> interface are precisely equivalent to |
70 |
|
* <tt>Deque</tt> methods as indicated in the following table:<p> |
71 |
|
* |
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 |
|
* |
131 |
|
* a deque is used as a queue or a stack; in either case, elements are |
132 |
|
* drawn from the beginning of the deque. |
133 |
|
* |
134 |
< |
* <p>This inteface provides two methods to to remove interior |
134 |
> |
* <p>This interface provides two methods to remove interior |
135 |
|
* elements, {@link #removeFirstOccurrence removeFirstOccurrence} and |
136 |
|
* {@link #removeLastOccurrence removeLastOccurrence}. Unlike the |
137 |
|
* {@link List} interface, this interface does not provide support for |
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); |
177 |
|
|
178 |
|
/** |
179 |
< |
* Inserts the specified element to the end of this deque unless it would |
179 |
> |
* Inserts the specified element at the end of this deque unless it would |
180 |
|
* violate capacity restrictions. When using a capacity-restricted deque, |
181 |
|
* this method is generally preferable to method <tt>addLast</tt> which |
182 |
|
* can fail to insert an element only by throwing an exception. |
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); |
203 |
|
|
204 |
|
/** |
205 |
< |
* Inserts the specified element to the end of this deque unless it would |
205 |
> |
* Inserts the specified element at the end of this deque unless it would |
206 |
|
* violate capacity restrictions. |
207 |
|
* |
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> |
301 |
> |
* @throws NullPointerException if the specified element is null and this |
302 |
> |
* deque does not permit null elements |
303 |
|
*/ |
304 |
< |
boolean removeFirstOccurrence(Object e); |
304 |
> |
boolean removeFirstOccurrence(Object o); |
305 |
|
|
306 |
|
/** |
307 |
|
* Removes the last occurrence of the specified element in this |
310 |
|
* such that <tt>(o==null ? e==null : o.equals(e))</tt> (if |
311 |
|
* such an element exists). |
312 |
|
* |
313 |
< |
* @param e element to be removed from this deque, if present |
313 |
> |
* @param o element to be removed from this deque, if present |
314 |
|
* @return <tt>true</tt> if the deque contained the specified element |
315 |
< |
* @throws NullPointerException if the specified element is <tt>null</tt> |
315 |
> |
* @throws NullPointerException if the specified element is null and this |
316 |
> |
* deque does not permit null elements |
317 |
|
*/ |
318 |
< |
boolean removeLastOccurrence(Object e); |
318 |
> |
boolean removeLastOccurrence(Object o); |
319 |
|
|
320 |
|
|
321 |
|
// *** Queue methods *** |
323 |
|
/** |
324 |
|
* Inserts the specified element into the queue represented by this deque |
325 |
|
* unless it would violate capacity restrictions. In other words, inserts |
326 |
< |
* the specified element to the end of this deque. When using a |
326 |
> |
* the specified element at the end of this deque. When using a |
327 |
|
* capacity-restricted deque, this method is generally preferable to the |
328 |
|
* {@link #add} method, which can fail to insert an element only by |
329 |
|
* throwing an exception. |
333 |
|
* @param e the element to insert |
334 |
|
* @return <tt>true</tt> if it was possible to insert the element, |
335 |
|
* else <tt>false</tt> |
336 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
336 |
> |
* @throws NullPointerException if the specified element is null and this |
337 |
|
* deque does not permit null elements |
338 |
|
*/ |
339 |
|
boolean offer(E e); |
341 |
|
/** |
342 |
|
* Inserts the specified element into the queue represented by this |
343 |
|
* deque unless it would violate capacity restrictions. In other words, |
344 |
< |
* inserts the specified element as the last element of this deque. |
344 |
> |
* inserts the specified element as the last element of this deque. |
345 |
|
* |
346 |
|
* <p>This method is equivalent to {@link #addLast}. |
347 |
|
* |
349 |
|
* @return <tt>true</tt> (as per the spec for {@link Collection#add}) |
350 |
|
* @throws IllegalStateException if it was not possible to insert |
351 |
|
* the element due to capacity restrictions |
352 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
352 |
> |
* @throws NullPointerException if the specified element is null and this |
353 |
|
* deque does not permit null elements |
354 |
|
*/ |
355 |
|
boolean add(E e); |
383 |
|
* Retrieves, but does not remove, the head of the queue represented by |
384 |
|
* this deque, returning <tt>null</tt> if this deque is empty. |
385 |
|
* |
386 |
< |
* <p>This method is equivalent to {@link #peekFirst()} |
386 |
> |
* <p>This method is equivalent to {@link #peekFirst()}. |
387 |
|
* |
388 |
|
* @return the head of the queue represented by this deque, or |
389 |
|
* <tt>null</tt> if this deque is empty |
395 |
|
* this deque. This method differs from the <tt>peek</tt> method only in |
396 |
|
* that it throws an exception if this deque is empty. |
397 |
|
* |
398 |
< |
* <p>This method is equivalent to {@link #getFirst()} |
398 |
> |
* <p>This method is equivalent to {@link #getFirst()}. |
399 |
|
* |
400 |
|
* @return the head of the queue represented by this deque |
401 |
|
* @throws NoSuchElementException if this deque is empty |
407 |
|
|
408 |
|
/** |
409 |
|
* Pushes an element onto the stack represented by this deque. In other |
410 |
< |
* words, inserts the element to the front this deque unless it would |
410 |
> |
* words, inserts the element at the front of this deque unless it would |
411 |
|
* violate capacity restrictions. |
412 |
|
* |
413 |
|
* <p>This method is equivalent to {@link #addFirst}. |
414 |
|
* |
415 |
+ |
* @param e the element to push |
416 |
|
* @throws IllegalStateException if it was not possible to insert |
417 |
|
* the element due to capacity restrictions |
418 |
< |
* @throws NullPointerException if <tt>e</tt> is null and this |
418 |
> |
* @throws NullPointerException if the specified element is null and this |
419 |
|
* deque does not permit null elements |
420 |
|
*/ |
421 |
|
void push(E e); |
422 |
|
|
423 |
|
/** |
424 |
|
* Pops an element from the stack represented by this deque. In other |
425 |
< |
* words, removes and returns the the first element of this deque. |
425 |
> |
* words, removes and returns the first element of this deque. |
426 |
|
* |
427 |
|
* <p>This method is equivalent to {@link #removeFirst()}. |
428 |
|
* |
438 |
|
/** |
439 |
|
* Returns an iterator over the elements in this deque. The elements |
440 |
|
* will be ordered from first (head) to last (tail). |
441 |
< |
* |
441 |
> |
* |
442 |
|
* @return an <tt>Iterator</tt> over the elements in this deque |
443 |
|
*/ |
444 |
|
Iterator<E> iterator(); |