25 |
|
* operations cannot fail. |
26 |
|
* |
27 |
|
* <p>The twelve methods described above are summarized in the |
28 |
< |
* following table:<p> |
28 |
> |
* following table: |
29 |
|
* |
30 |
+ |
* <p> |
31 |
|
* <table BORDER CELLPADDING=3 CELLSPACING=1> |
32 |
|
* <tr> |
33 |
|
* <td></td> |
37 |
|
* <tr> |
38 |
|
* <td></td> |
39 |
|
* <td ALIGN=CENTER><em>Throws exception</em></td> |
40 |
< |
* <td ALIGN=CENTER><em>Returns special value</em></td> |
40 |
> |
* <td ALIGN=CENTER><em>Special value</em></td> |
41 |
|
* <td ALIGN=CENTER><em>Throws exception</em></td> |
42 |
< |
* <td ALIGN=CENTER><em>Returns special value</em></td> |
42 |
> |
* <td ALIGN=CENTER><em>Special value</em></td> |
43 |
|
* </tr> |
44 |
|
* <tr> |
45 |
|
* <td><b>Insert</b></td> |
68 |
|
* used as a queue, FIFO (First-In-First-Out) behavior results. Elements are |
69 |
|
* added at the end of the deque and removed from the beginning. The methods |
70 |
|
* inherited from the <tt>Queue</tt> interface are precisely equivalent to |
71 |
< |
* <tt>Deque</tt> methods as indicated in the following table:<p> |
71 |
> |
* <tt>Deque</tt> methods as indicated in the following table: |
72 |
|
* |
73 |
+ |
* <p> |
74 |
|
* <table BORDER CELLPADDING=3 CELLSPACING=1> |
75 |
|
* <tr> |
76 |
|
* <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td> |
77 |
|
* <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td> |
78 |
|
* </tr> |
79 |
|
* <tr> |
78 |
– |
* <tr> |
79 |
– |
* <td>{@link java.util.Queue#offer offer(e)}</td> |
80 |
– |
* <td>{@link #offerLast offerLast(e)}</td> |
81 |
– |
* </tr> |
82 |
– |
* <tr> |
80 |
|
* <td>{@link java.util.Queue#add add(e)}</td> |
81 |
|
* <td>{@link #addLast addLast(e)}</td> |
82 |
< |
* </tr> |
83 |
< |
* <tr> |
84 |
< |
* <td>{@link java.util.Queue#poll poll()}</td> |
85 |
< |
* <td>{@link #pollFirst pollFirst()}</td> |
86 |
< |
* </tr> |
87 |
< |
* <tr> |
82 |
> |
* </tr> |
83 |
> |
* <tr> |
84 |
> |
* <td>{@link java.util.Queue#offer offer(e)}</td> |
85 |
> |
* <td>{@link #offerLast offerLast(e)}</td> |
86 |
> |
* </tr> |
87 |
> |
* <tr> |
88 |
|
* <td>{@link java.util.Queue#remove remove()}</td> |
89 |
|
* <td>{@link #removeFirst removeFirst()}</td> |
90 |
< |
* </tr> |
91 |
< |
* <tr> |
92 |
< |
* <td>{@link java.util.Queue#peek peek()}</td> |
93 |
< |
* <td>{@link #peek peekFirst()}</td> |
94 |
< |
* </tr> |
95 |
< |
* <tr> |
90 |
> |
* </tr> |
91 |
> |
* <tr> |
92 |
> |
* <td>{@link java.util.Queue#poll poll()}</td> |
93 |
> |
* <td>{@link #pollFirst pollFirst()}</td> |
94 |
> |
* </tr> |
95 |
> |
* <tr> |
96 |
|
* <td>{@link java.util.Queue#element element()}</td> |
97 |
|
* <td>{@link #getFirst getFirst()}</td> |
98 |
< |
* </tr> |
98 |
> |
* </tr> |
99 |
> |
* <tr> |
100 |
> |
* <td>{@link java.util.Queue#peek peek()}</td> |
101 |
> |
* <td>{@link #peek peekFirst()}</td> |
102 |
> |
* </tr> |
103 |
|
* </table> |
104 |
|
* |
105 |
|
* <p>Deques can also be used as LIFO (Last-In-First-Out) stacks. This |
106 |
|
* interface should be used in preference to the legacy {@link Stack} class. |
107 |
|
* When a deque is used as a stack, elements are pushed and popped from the |
108 |
|
* beginning of the deque. Stack methods are precisely equivalent to |
109 |
< |
* <tt>Deque</tt> methods as indicated in the table below:<p> |
109 |
> |
* <tt>Deque</tt> methods as indicated in the table below: |
110 |
|
* |
111 |
+ |
* <p> |
112 |
|
* <table BORDER CELLPADDING=3 CELLSPACING=1> |
113 |
|
* <tr> |
114 |
|
* <td ALIGN=CENTER> <b>Stack Method</b></td> |
115 |
|
* <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td> |
116 |
|
* </tr> |
117 |
|
* <tr> |
116 |
– |
* <tr> |
118 |
|
* <td>{@link #push push(e)}</td> |
119 |
|
* <td>{@link #addFirst addFirst(e)}</td> |
120 |
< |
* </tr> |
121 |
< |
* <tr> |
120 |
> |
* </tr> |
121 |
> |
* <tr> |
122 |
|
* <td>{@link #pop pop()}</td> |
123 |
|
* <td>{@link #removeFirst removeFirst()}</td> |
124 |
< |
* </tr> |
125 |
< |
* <tr> |
124 |
> |
* </tr> |
125 |
> |
* <tr> |
126 |
|
* <td>{@link #peek peek()}</td> |
127 |
|
* <td>{@link #peekFirst peekFirst()}</td> |
128 |
< |
* </tr> |
128 |
> |
* </tr> |
129 |
|
* </table> |
130 |
|
* |
131 |
|
* <p>Note that the {@link #peek peek} method works equally well when |
134 |
|
* |
135 |
|
* <p>This interface provides two methods to remove interior |
136 |
|
* elements, {@link #removeFirstOccurrence removeFirstOccurrence} and |
137 |
< |
* {@link #removeLastOccurrence removeLastOccurrence}. Unlike the |
138 |
< |
* {@link List} interface, this interface does not provide support for |
139 |
< |
* indexed access to elements. |
137 |
> |
* {@link #removeLastOccurrence removeLastOccurrence}. |
138 |
> |
* |
139 |
> |
* <p>Unlike the {@link List} interface, this interface does not |
140 |
> |
* provide support for indexed access to elements. |
141 |
|
* |
142 |
|
* <p>While <tt>Deque</tt> implementations are not strictly required |
143 |
|
* to prohibit the insertion of null elements, they are strongly |
164 |
|
|
165 |
|
public interface Deque<E> extends Queue<E> { |
166 |
|
/** |
167 |
+ |
* Inserts the specified element at the front of this deque if it is |
168 |
+ |
* possible to do so immediately without violating capacity restrictions. |
169 |
+ |
* When using a capacity-restricted deque, it is generally preferable to |
170 |
+ |
* use method {@link #offerFirst}. |
171 |
+ |
* |
172 |
+ |
* @param e the element to add |
173 |
+ |
* @throws IllegalStateException if the element cannot be added at this |
174 |
+ |
* time due to capacity restrictions |
175 |
+ |
* @throws ClassCastException if the class of the specified element |
176 |
+ |
* prevents it from being added to this deque |
177 |
+ |
* @throws NullPointerException if the specified element is null and this |
178 |
+ |
* deque does not permit null elements |
179 |
+ |
* @throws IllegalArgumentException if some property of the specified |
180 |
+ |
* element prevents it from being added to this deque |
181 |
+ |
*/ |
182 |
+ |
void addFirst(E e); |
183 |
+ |
|
184 |
+ |
/** |
185 |
+ |
* Inserts the specified element at the end of this deque if it is |
186 |
+ |
* possible to do so immediately without violating capacity restrictions. |
187 |
+ |
* When using a capacity-restricted deque, it is generally preferable to |
188 |
+ |
* use method {@link #offerLast}. |
189 |
+ |
* |
190 |
+ |
* @param e the element to add |
191 |
+ |
* @throws IllegalStateException if the element cannot be added at this |
192 |
+ |
* time due to capacity restrictions |
193 |
+ |
* @throws ClassCastException if the class of the specified element |
194 |
+ |
* prevents it from being added to this deque |
195 |
+ |
* @throws NullPointerException if the specified element is null and this |
196 |
+ |
* deque does not permit null elements |
197 |
+ |
* @throws IllegalArgumentException if some property of the specified |
198 |
+ |
* element prevents it from being added to this deque |
199 |
+ |
*/ |
200 |
+ |
void addLast(E e); |
201 |
+ |
|
202 |
+ |
/** |
203 |
|
* Inserts the specified element at the front of this deque unless it would |
204 |
|
* violate capacity restrictions. When using a capacity-restricted deque, |
205 |
< |
* this method is generally preferable to method <tt>addFirst</tt>, which |
206 |
< |
* can fail to insert an element only by throwing an exception. |
205 |
> |
* this method is generally preferable to the {@link #addFirst} method, |
206 |
> |
* which can fail to insert an element only by throwing an exception. |
207 |
|
* |
208 |
< |
* @param e the element to insert |
208 |
> |
* @param e the element to add |
209 |
|
* @return <tt>true</tt> if it was possible to insert the element, |
210 |
< |
* else <tt>false</tt> |
210 |
> |
* else <tt>false</tt> |
211 |
> |
* @throws ClassCastException if the class of the specified element |
212 |
> |
* prevents it from being added to this deque |
213 |
|
* @throws NullPointerException if the specified element is null and this |
214 |
< |
* deque does not permit null elements |
214 |
> |
* deque does not permit null elements |
215 |
> |
* @throws IllegalArgumentException if some property of the specified |
216 |
> |
* element prevents it from being added to this deque |
217 |
|
*/ |
218 |
|
boolean offerFirst(E e); |
219 |
|
|
220 |
|
/** |
221 |
|
* Inserts the specified element at the end of this deque unless it would |
222 |
|
* violate capacity restrictions. When using a capacity-restricted deque, |
223 |
< |
* this method is generally preferable to method <tt>addLast</tt> which |
224 |
< |
* can fail to insert an element only by throwing an exception. |
223 |
> |
* this method is generally preferable to the {@link #addLast} method, |
224 |
> |
* which can fail to insert an element only by throwing an exception. |
225 |
|
* |
226 |
< |
* @param e the element to insert |
226 |
> |
* @param e the element to add |
227 |
|
* @return <tt>true</tt> if it was possible to insert the element, |
228 |
< |
* else <tt>false</tt> |
228 |
> |
* else <tt>false</tt> |
229 |
> |
* @throws ClassCastException if the class of the specified element |
230 |
> |
* prevents it from being added to this deque |
231 |
|
* @throws NullPointerException if the specified element is null and this |
232 |
< |
* deque does not permit null elements |
232 |
> |
* deque does not permit null elements |
233 |
> |
* @throws IllegalArgumentException if some property of the specified |
234 |
> |
* element prevents it from being added to this deque |
235 |
|
*/ |
236 |
|
boolean offerLast(E e); |
237 |
|
|
238 |
|
/** |
239 |
< |
* Inserts the specified element at the front of this deque unless it |
240 |
< |
* would violate capacity restrictions. |
239 |
> |
* Retrieves and removes the first element of this deque. This method |
240 |
> |
* differs from {@link #pollFirst} only in that it throws an exception |
241 |
> |
* if this deque is empty. |
242 |
|
* |
243 |
< |
* @param e the element to insert |
244 |
< |
* @throws IllegalStateException if it was not possible to insert |
198 |
< |
* the element due to capacity restrictions |
199 |
< |
* @throws NullPointerException if the specified element is null and this |
200 |
< |
* deque does not permit null elements |
243 |
> |
* @return the head of this deque |
244 |
> |
* @throws NoSuchElementException if this deque is empty |
245 |
|
*/ |
246 |
< |
void addFirst(E e); |
246 |
> |
E removeFirst(); |
247 |
|
|
248 |
|
/** |
249 |
< |
* Inserts the specified element at the end of this deque unless it would |
250 |
< |
* violate capacity restrictions. |
249 |
> |
* Retrieves and removes the last element of this deque. This method |
250 |
> |
* differs from {@link #pollLast} only in that it throws an exception if |
251 |
> |
* this deque is empty. |
252 |
|
* |
253 |
< |
* @param e the element to insert |
254 |
< |
* @throws IllegalStateException if it was not possible to insert |
210 |
< |
* the element due to capacity restrictions |
211 |
< |
* @throws NullPointerException if the specified element is null and this |
212 |
< |
* deque does not permit null elements |
253 |
> |
* @return the tail of this deque |
254 |
> |
* @throws NoSuchElementException if this deque is empty |
255 |
|
*/ |
256 |
< |
void addLast(E e); |
256 |
> |
E removeLast(); |
257 |
|
|
258 |
|
/** |
259 |
< |
* Retrieves and removes the first element of this deque, or |
260 |
< |
* <tt>null</tt> if this deque is empty. |
259 |
> |
* Retrieves and removes the first element of this deque, |
260 |
> |
* or returns <tt>null</tt> if this deque is empty. |
261 |
|
* |
262 |
< |
* @return the first element of this deque, or <tt>null</tt> if |
221 |
< |
* this deque is empty |
262 |
> |
* @return the head of this deque, or <tt>null</tt> if this deque is empty |
263 |
|
*/ |
264 |
|
E pollFirst(); |
265 |
|
|
266 |
|
/** |
267 |
< |
* Retrieves and removes the last element of this deque, or |
268 |
< |
* <tt>null</tt> if this deque is empty. |
267 |
> |
* Retrieves and removes the last element of this deque, |
268 |
> |
* or returns <tt>null</tt> if this deque is empty. |
269 |
|
* |
270 |
< |
* @return the last element of this deque, or <tt>null</tt> if |
230 |
< |
* this deque is empty |
270 |
> |
* @return the tail of this deque, or <tt>null</tt> if this deque is empty |
271 |
|
*/ |
272 |
|
E pollLast(); |
273 |
|
|
274 |
|
/** |
275 |
< |
* Removes and returns the first element of this deque. This method |
276 |
< |
* differs from the <tt>pollFirst</tt> method only in that it throws an |
275 |
> |
* Retrieves, but does not remove, the first element of this deque. |
276 |
> |
* This method differs from {@link #peekFirst} only in that it throws an |
277 |
|
* exception if this deque is empty. |
278 |
|
* |
279 |
< |
* @return the first element of this deque |
279 |
> |
* @return the head of this deque |
280 |
|
* @throws NoSuchElementException if this deque is empty |
281 |
|
*/ |
282 |
< |
E removeFirst(); |
282 |
> |
E getFirst(); |
283 |
|
|
284 |
|
/** |
285 |
< |
* Retrieves and removes the last element of this deque. This method |
286 |
< |
* differs from the <tt>pollLast</tt> method only in that it throws an |
285 |
> |
* Retrieves, but does not remove, the last element of this deque. |
286 |
> |
* This method differs from {@link #peekLast} only in that it throws an |
287 |
|
* exception if this deque is empty. |
288 |
|
* |
289 |
< |
* @return the last element of this deque |
289 |
> |
* @return the tail of this deque |
290 |
|
* @throws NoSuchElementException if this deque is empty |
291 |
|
*/ |
292 |
< |
E removeLast(); |
292 |
> |
E getLast(); |
293 |
|
|
294 |
|
/** |
295 |
|
* Retrieves, but does not remove, the first element of this deque, |
296 |
< |
* returning <tt>null</tt> if this deque is empty. |
296 |
> |
* or returns <tt>null</tt> if this deque is empty. |
297 |
|
* |
298 |
< |
* @return the first element of this deque, or <tt>null</tt> if |
259 |
< |
* this deque is empty |
298 |
> |
* @return the head of this deque, or <tt>null</tt> if this deque is empty |
299 |
|
*/ |
300 |
|
E peekFirst(); |
301 |
|
|
302 |
|
/** |
303 |
|
* Retrieves, but does not remove, the last element of this deque, |
304 |
< |
* returning <tt>null</tt> if this deque is empty. |
304 |
> |
* or returns <tt>null</tt> if this deque is empty. |
305 |
|
* |
306 |
< |
* @return the last element of this deque, or <tt>null</tt> if this deque |
268 |
< |
* is empty |
306 |
> |
* @return the tail of this deque, or <tt>null</tt> if this deque is empty |
307 |
|
*/ |
308 |
|
E peekLast(); |
309 |
|
|
310 |
|
/** |
311 |
< |
* Retrieves, but does not remove, the first element of this |
312 |
< |
* deque. This method differs from the <tt>peekFirst</tt> method only |
313 |
< |
* in that it throws an exception if this deque is empty. |
314 |
< |
* |
315 |
< |
* @return the first element of this deque |
316 |
< |
* @throws NoSuchElementException if this deque is empty |
317 |
< |
*/ |
280 |
< |
E getFirst(); |
281 |
< |
|
282 |
< |
/** |
283 |
< |
* Retrieves, but does not remove, the last element of this |
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 |
288 |
< |
* @throws NoSuchElementException if this deque is empty |
289 |
< |
*/ |
290 |
< |
E getLast(); |
291 |
< |
|
292 |
< |
/** |
293 |
< |
* Removes the first occurrence of the specified element in this |
294 |
< |
* deque. If the deque does not contain the element, it is |
295 |
< |
* unchanged. More formally, removes the first element <tt>e</tt> |
296 |
< |
* such that <tt>(o==null ? e==null : o.equals(e))</tt> (if |
297 |
< |
* such an element exists). |
311 |
> |
* Removes the first occurrence of the specified element from this deque. |
312 |
> |
* If the deque does not contain the element, it is unchanged. |
313 |
> |
* More formally, removes the first element <tt>e</tt> such that |
314 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt> |
315 |
> |
* (if such an element exists). |
316 |
> |
* Returns true if this deque contained the specified element (or |
317 |
> |
* equivalently, if this deque changed as a result of the call). |
318 |
|
* |
319 |
|
* @param o element to be removed from this deque, if present |
320 |
< |
* @return <tt>true</tt> if the deque contained the specified element |
320 |
> |
* @return <tt>true</tt> if an element was removed as a result of this call |
321 |
> |
* @throws ClassCastException if the class of the specified element |
322 |
> |
* is incompatible with this deque (optional) |
323 |
|
* @throws NullPointerException if the specified element is null and this |
324 |
< |
* deque does not permit null elements |
324 |
> |
* deque does not permit null elements (optional) |
325 |
|
*/ |
326 |
|
boolean removeFirstOccurrence(Object o); |
327 |
|
|
328 |
|
/** |
329 |
< |
* Removes the last occurrence of the specified element in this |
330 |
< |
* deque. If the deque does not contain the element, it is |
331 |
< |
* unchanged. More formally, removes the last element <tt>e</tt> |
332 |
< |
* such that <tt>(o==null ? e==null : o.equals(e))</tt> (if |
333 |
< |
* such an element exists). |
329 |
> |
* Removes the last occurrence of the specified element from this deque. |
330 |
> |
* If the deque does not contain the element, it is unchanged. |
331 |
> |
* More formally, removes the last element <tt>e</tt> such that |
332 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt> |
333 |
> |
* (if such an element exists). |
334 |
> |
* Returns true if this deque contained the specified element (or |
335 |
> |
* equivalently, if this deque changed as a result of the call). |
336 |
|
* |
337 |
|
* @param o element to be removed from this deque, if present |
338 |
< |
* @return <tt>true</tt> if the deque contained the specified element |
338 |
> |
* @return <tt>true</tt> if an element was removed as a result of this call |
339 |
> |
* @throws ClassCastException if the class of the specified element |
340 |
> |
* is incompatible with this deque (optional) |
341 |
|
* @throws NullPointerException if the specified element is null and this |
342 |
< |
* deque does not permit null elements |
342 |
> |
* deque does not permit null elements (optional) |
343 |
|
*/ |
344 |
|
boolean removeLastOccurrence(Object o); |
345 |
|
|
320 |
– |
|
346 |
|
// *** Queue methods *** |
347 |
|
|
348 |
|
/** |
349 |
|
* Inserts the specified element into the queue represented by this deque |
350 |
< |
* unless it would violate capacity restrictions. In other words, inserts |
351 |
< |
* the specified element at the end of this deque. When using a |
352 |
< |
* capacity-restricted deque, this method is generally preferable to the |
353 |
< |
* {@link #add} method, which can fail to insert an element only by |
354 |
< |
* throwing an exception. |
350 |
> |
* (in other words, at the tail of this deque) if it is possible to do so |
351 |
> |
* immediately without violating capacity restrictions, returning |
352 |
> |
* <tt>true</tt> upon success and throwing an |
353 |
> |
* <tt>IllegalStateException</tt> if no space is currently available. |
354 |
> |
* When using a capacity-restricted deque, it is generally preferable to |
355 |
> |
* use {@link #offer(Object) offer}. |
356 |
|
* |
357 |
< |
* <p>This method is equivalent to {@link #offerLast}. |
357 |
> |
* <p>This method is equivalent to {@link #addLast(Object) addLast}. |
358 |
|
* |
359 |
< |
* @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 the specified element is null and this |
337 |
< |
* deque does not permit null elements |
338 |
< |
*/ |
339 |
< |
boolean offer(E e); |
340 |
< |
|
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. |
345 |
< |
* |
346 |
< |
* <p>This method is equivalent to {@link #addLast}. |
347 |
< |
* |
348 |
< |
* @param e the element to insert |
359 |
> |
* @param e the element to add |
360 |
|
* @return <tt>true</tt> (as per the spec for {@link Collection#add}) |
361 |
< |
* @throws IllegalStateException if it was not possible to insert |
362 |
< |
* the element due to capacity restrictions |
361 |
> |
* @throws IllegalStateException if the element cannot be added at this |
362 |
> |
* time due to capacity restrictions |
363 |
> |
* @throws ClassCastException if the class of the specified element |
364 |
> |
* prevents it from being added to this deque |
365 |
|
* @throws NullPointerException if the specified element is null and this |
366 |
< |
* deque does not permit null elements |
366 |
> |
* deque does not permit null elements |
367 |
> |
* @throws IllegalArgumentException if some property of the specified |
368 |
> |
* element prevents it from being added to this deque |
369 |
|
*/ |
370 |
|
boolean add(E e); |
371 |
|
|
372 |
|
/** |
373 |
< |
* Retrieves and removes the head of the queue represented by |
374 |
< |
* this deque, or <tt>null</tt> if this deque is empty. In other words, |
375 |
< |
* retrieves and removes the first element of this deque, or <tt>null</tt> |
376 |
< |
* if this deque is empty. |
373 |
> |
* Inserts the specified element into the queue represented by this deque |
374 |
> |
* (in other words, at the tail of this deque) if it is possible to do so |
375 |
> |
* immediately without violating capacity restrictions, returning |
376 |
> |
* <tt>true</tt> upon success and <tt>false</tt> if no space is currently |
377 |
> |
* available. When using a capacity-restricted deque, this method is |
378 |
> |
* generally preferable to the {@link #add} method, which can fail to |
379 |
> |
* insert an element only by throwing an exception. |
380 |
|
* |
381 |
< |
* <p>This method is equivalent to {@link #pollFirst()}. |
381 |
> |
* <p>This method is equivalent to {@link #offerLast}. |
382 |
|
* |
383 |
< |
* @return the first element of this deque, or <tt>null</tt> if |
384 |
< |
* this deque is empty |
383 |
> |
* @param e the element to add |
384 |
> |
* @return <tt>true</tt> if the element was added to this deque, else |
385 |
> |
* <tt>false</tt> |
386 |
> |
* @throws ClassCastException if the class of the specified element |
387 |
> |
* prevents it from being added to this deque |
388 |
> |
* @throws NullPointerException if the specified element is null and this |
389 |
> |
* deque does not permit null elements |
390 |
> |
* @throws IllegalArgumentException if some property of the specified |
391 |
> |
* element prevents it from being added to this deque |
392 |
|
*/ |
393 |
< |
E poll(); |
393 |
> |
boolean offer(E e); |
394 |
|
|
395 |
|
/** |
396 |
< |
* Retrieves and removes the head of the queue represented by this deque. |
397 |
< |
* This method differs from the <tt>poll</tt> method only in that it |
398 |
< |
* throws an exception if this deque is empty. |
396 |
> |
* Retrieves and removes the head of the queue represented by this deque |
397 |
> |
* (in other words, the first element of this deque). |
398 |
> |
* This method differs from {@link #poll} only in that it throws an |
399 |
> |
* exception if this deque is empty. |
400 |
|
* |
401 |
|
* <p>This method is equivalent to {@link #removeFirst()}. |
402 |
|
* |
406 |
|
E remove(); |
407 |
|
|
408 |
|
/** |
409 |
< |
* Retrieves, but does not remove, the head of the queue represented by |
410 |
< |
* this deque, returning <tt>null</tt> if this deque is empty. |
409 |
> |
* Retrieves and removes the head of the queue represented by this deque |
410 |
> |
* (in other words, the first element of this deque), or returns |
411 |
> |
* <tt>null</tt> if this deque is empty. |
412 |
|
* |
413 |
< |
* <p>This method is equivalent to {@link #peekFirst()}. |
413 |
> |
* <p>This method is equivalent to {@link #pollFirst()}. |
414 |
|
* |
415 |
< |
* @return the head of the queue represented by this deque, or |
416 |
< |
* <tt>null</tt> if this deque is empty |
415 |
> |
* @return the first element of this deque, or <tt>null</tt> if |
416 |
> |
* this deque is empty |
417 |
|
*/ |
418 |
< |
E peek(); |
418 |
> |
E poll(); |
419 |
|
|
420 |
|
/** |
421 |
|
* Retrieves, but does not remove, the head of the queue represented by |
422 |
< |
* this deque. This method differs from the <tt>peek</tt> method only in |
423 |
< |
* that it throws an exception if this deque is empty. |
422 |
> |
* this deque (in other words, the first element of this deque). |
423 |
> |
* This method differs from {@link #peek} only in that it throws an |
424 |
> |
* exception if this deque is empty. |
425 |
|
* |
426 |
|
* <p>This method is equivalent to {@link #getFirst()}. |
427 |
|
* |
430 |
|
*/ |
431 |
|
E element(); |
432 |
|
|
433 |
+ |
/** |
434 |
+ |
* Retrieves, but does not remove, the head of the queue represented by |
435 |
+ |
* this deque (in other words, the first element of this deque), or |
436 |
+ |
* returns <tt>null</tt> if this deque is empty. |
437 |
+ |
* |
438 |
+ |
* <p>This method is equivalent to {@link #peekFirst()}. |
439 |
+ |
* |
440 |
+ |
* @return the head of the queue represented by this deque, or |
441 |
+ |
* <tt>null</tt> if this deque is empty |
442 |
+ |
*/ |
443 |
+ |
E peek(); |
444 |
+ |
|
445 |
|
|
446 |
|
// *** Stack methods *** |
447 |
|
|
448 |
|
/** |
449 |
< |
* Pushes an element onto the stack represented by this deque. In other |
450 |
< |
* words, inserts the element at the front of this deque unless it would |
451 |
< |
* violate capacity restrictions. |
449 |
> |
* Pushes an element onto the stack represented by this deque (in other |
450 |
> |
* words, at the head of this deque) if it is possible to do so |
451 |
> |
* immediately without violating capacity restrictions, returning |
452 |
> |
* <tt>true</tt> upon success and throwing an |
453 |
> |
* <tt>IllegalStateException</tt> if no space is currently available. |
454 |
|
* |
455 |
|
* <p>This method is equivalent to {@link #addFirst}. |
456 |
|
* |
457 |
|
* @param e the element to push |
458 |
< |
* @throws IllegalStateException if it was not possible to insert |
459 |
< |
* the element due to capacity restrictions |
458 |
> |
* @throws IllegalStateException if the element cannot be added at this |
459 |
> |
* time due to capacity restrictions |
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 and this |
463 |
< |
* deque does not permit null elements |
463 |
> |
* deque does not permit null elements |
464 |
> |
* @throws IllegalArgumentException if some property of the specified |
465 |
> |
* element prevents it from being added to this deque |
466 |
|
*/ |
467 |
|
void push(E e); |
468 |
|
|
473 |
|
* <p>This method is equivalent to {@link #removeFirst()}. |
474 |
|
* |
475 |
|
* @return the element at the front of this deque (which is the top |
476 |
< |
* of the stack represented by this deque) |
476 |
> |
* of the stack represented by this deque) |
477 |
|
* @throws NoSuchElementException if this deque is empty |
478 |
|
*/ |
479 |
|
E pop(); |
480 |
|
|
481 |
|
|
482 |
< |
// *** Collection Method *** |
482 |
> |
// *** Collection methods *** |
483 |
> |
|
484 |
> |
/** |
485 |
> |
* Removes the first occurrence of the specified element from this deque. |
486 |
> |
* If the deque does not contain the element, it is unchanged. |
487 |
> |
* More formally, removes the first element <tt>e</tt> such that |
488 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt> |
489 |
> |
* (if such an element exists). |
490 |
> |
* Returns true if this deque contained the specified element (or |
491 |
> |
* equivalently, if this deque changed as a result of the call). |
492 |
> |
* |
493 |
> |
* <p>This method is equivalent to {@link #removeFirstOccurrence}. |
494 |
> |
* |
495 |
> |
* @param o element to be removed from this deque, if present |
496 |
> |
* @return <tt>true</tt> if an element was removed as a result of this call |
497 |
> |
* @throws ClassCastException if the class of the specified element |
498 |
> |
* is incompatible with this deque (optional) |
499 |
> |
* @throws NullPointerException if the specified element is null and this |
500 |
> |
* deque does not permit null elements (optional) |
501 |
> |
*/ |
502 |
> |
boolean remove(Object o); |
503 |
> |
|
504 |
> |
/** |
505 |
> |
* Returns <tt>true</tt> if this deque contains the specified element. |
506 |
> |
* More formally, returns <tt>true</tt> if and only if this deque contains |
507 |
> |
* at least one element <tt>e</tt> such that |
508 |
> |
* <tt>(o==null ? e==null : o.equals(e))</tt>. |
509 |
> |
* |
510 |
> |
* @param o element whose presence in this deque is to be tested |
511 |
> |
* @return <tt>true</tt> if this deque contains the specified element |
512 |
> |
* @throws ClassCastException if the type of the specified element |
513 |
> |
* is incompatible with this deque (optional) |
514 |
> |
* @throws NullPointerException if the specified element is null and this |
515 |
> |
* deque does not permit null elements (optional) |
516 |
> |
*/ |
517 |
> |
boolean contains(Object o); |
518 |
> |
|
519 |
> |
/** |
520 |
> |
* Returns the number of elements in this deque. |
521 |
> |
* |
522 |
> |
* @return the number of elements in this deque |
523 |
> |
*/ |
524 |
> |
public int size(); |
525 |
|
|
526 |
|
/** |
527 |
|
* Returns an iterator over the elements in this deque. The elements |