jaroslav@597
|
1 |
/*
|
jaroslav@597
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@597
|
3 |
*
|
jaroslav@597
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@597
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@597
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@597
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@597
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@597
|
9 |
*
|
jaroslav@597
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@597
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@597
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@597
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@597
|
14 |
* accompanied this code).
|
jaroslav@597
|
15 |
*
|
jaroslav@597
|
16 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@597
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@597
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@597
|
19 |
*
|
jaroslav@597
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@597
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@597
|
22 |
* questions.
|
jaroslav@597
|
23 |
*/
|
jaroslav@597
|
24 |
|
jaroslav@597
|
25 |
/*
|
jaroslav@597
|
26 |
* This file is available under and governed by the GNU General Public
|
jaroslav@597
|
27 |
* License version 2 only, as published by the Free Software Foundation.
|
jaroslav@597
|
28 |
* However, the following notice accompanied the original version of this
|
jaroslav@597
|
29 |
* file:
|
jaroslav@597
|
30 |
*
|
jaroslav@597
|
31 |
* Written by Doug Lea and Josh Bloch with assistance from members of
|
jaroslav@597
|
32 |
* JCP JSR-166 Expert Group and released to the public domain, as explained
|
jaroslav@597
|
33 |
* at http://creativecommons.org/publicdomain/zero/1.0/
|
jaroslav@597
|
34 |
*/
|
jaroslav@597
|
35 |
|
jaroslav@597
|
36 |
package java.util;
|
jaroslav@597
|
37 |
|
jaroslav@597
|
38 |
/**
|
jaroslav@597
|
39 |
* A linear collection that supports element insertion and removal at
|
jaroslav@597
|
40 |
* both ends. The name <i>deque</i> is short for "double ended queue"
|
jaroslav@597
|
41 |
* and is usually pronounced "deck". Most <tt>Deque</tt>
|
jaroslav@597
|
42 |
* implementations place no fixed limits on the number of elements
|
jaroslav@597
|
43 |
* they may contain, but this interface supports capacity-restricted
|
jaroslav@597
|
44 |
* deques as well as those with no fixed size limit.
|
jaroslav@597
|
45 |
*
|
jaroslav@597
|
46 |
* <p>This interface defines methods to access the elements at both
|
jaroslav@597
|
47 |
* ends of the deque. Methods are provided to insert, remove, and
|
jaroslav@597
|
48 |
* examine the element. Each of these methods exists in two forms:
|
jaroslav@597
|
49 |
* one throws an exception if the operation fails, the other returns a
|
jaroslav@597
|
50 |
* special value (either <tt>null</tt> or <tt>false</tt>, depending on
|
jaroslav@597
|
51 |
* the operation). The latter form of the insert operation is
|
jaroslav@597
|
52 |
* designed specifically for use with capacity-restricted
|
jaroslav@597
|
53 |
* <tt>Deque</tt> implementations; in most implementations, insert
|
jaroslav@597
|
54 |
* operations cannot fail.
|
jaroslav@597
|
55 |
*
|
jaroslav@597
|
56 |
* <p>The twelve methods described above are summarized in the
|
jaroslav@597
|
57 |
* following table:
|
jaroslav@597
|
58 |
*
|
jaroslav@597
|
59 |
* <p>
|
jaroslav@597
|
60 |
* <table BORDER CELLPADDING=3 CELLSPACING=1>
|
jaroslav@597
|
61 |
* <tr>
|
jaroslav@597
|
62 |
* <td></td>
|
jaroslav@597
|
63 |
* <td ALIGN=CENTER COLSPAN = 2> <b>First Element (Head)</b></td>
|
jaroslav@597
|
64 |
* <td ALIGN=CENTER COLSPAN = 2> <b>Last Element (Tail)</b></td>
|
jaroslav@597
|
65 |
* </tr>
|
jaroslav@597
|
66 |
* <tr>
|
jaroslav@597
|
67 |
* <td></td>
|
jaroslav@597
|
68 |
* <td ALIGN=CENTER><em>Throws exception</em></td>
|
jaroslav@597
|
69 |
* <td ALIGN=CENTER><em>Special value</em></td>
|
jaroslav@597
|
70 |
* <td ALIGN=CENTER><em>Throws exception</em></td>
|
jaroslav@597
|
71 |
* <td ALIGN=CENTER><em>Special value</em></td>
|
jaroslav@597
|
72 |
* </tr>
|
jaroslav@597
|
73 |
* <tr>
|
jaroslav@597
|
74 |
* <td><b>Insert</b></td>
|
jaroslav@597
|
75 |
* <td>{@link #addFirst addFirst(e)}</td>
|
jaroslav@597
|
76 |
* <td>{@link #offerFirst offerFirst(e)}</td>
|
jaroslav@597
|
77 |
* <td>{@link #addLast addLast(e)}</td>
|
jaroslav@597
|
78 |
* <td>{@link #offerLast offerLast(e)}</td>
|
jaroslav@597
|
79 |
* </tr>
|
jaroslav@597
|
80 |
* <tr>
|
jaroslav@597
|
81 |
* <td><b>Remove</b></td>
|
jaroslav@597
|
82 |
* <td>{@link #removeFirst removeFirst()}</td>
|
jaroslav@597
|
83 |
* <td>{@link #pollFirst pollFirst()}</td>
|
jaroslav@597
|
84 |
* <td>{@link #removeLast removeLast()}</td>
|
jaroslav@597
|
85 |
* <td>{@link #pollLast pollLast()}</td>
|
jaroslav@597
|
86 |
* </tr>
|
jaroslav@597
|
87 |
* <tr>
|
jaroslav@597
|
88 |
* <td><b>Examine</b></td>
|
jaroslav@597
|
89 |
* <td>{@link #getFirst getFirst()}</td>
|
jaroslav@597
|
90 |
* <td>{@link #peekFirst peekFirst()}</td>
|
jaroslav@597
|
91 |
* <td>{@link #getLast getLast()}</td>
|
jaroslav@597
|
92 |
* <td>{@link #peekLast peekLast()}</td>
|
jaroslav@597
|
93 |
* </tr>
|
jaroslav@597
|
94 |
* </table>
|
jaroslav@597
|
95 |
*
|
jaroslav@597
|
96 |
* <p>This interface extends the {@link Queue} interface. When a deque is
|
jaroslav@597
|
97 |
* used as a queue, FIFO (First-In-First-Out) behavior results. Elements are
|
jaroslav@597
|
98 |
* added at the end of the deque and removed from the beginning. The methods
|
jaroslav@597
|
99 |
* inherited from the <tt>Queue</tt> interface are precisely equivalent to
|
jaroslav@597
|
100 |
* <tt>Deque</tt> methods as indicated in the following table:
|
jaroslav@597
|
101 |
*
|
jaroslav@597
|
102 |
* <p>
|
jaroslav@597
|
103 |
* <table BORDER CELLPADDING=3 CELLSPACING=1>
|
jaroslav@597
|
104 |
* <tr>
|
jaroslav@597
|
105 |
* <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>
|
jaroslav@597
|
106 |
* <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
|
jaroslav@597
|
107 |
* </tr>
|
jaroslav@597
|
108 |
* <tr>
|
jaroslav@597
|
109 |
* <td>{@link java.util.Queue#add add(e)}</td>
|
jaroslav@597
|
110 |
* <td>{@link #addLast addLast(e)}</td>
|
jaroslav@597
|
111 |
* </tr>
|
jaroslav@597
|
112 |
* <tr>
|
jaroslav@597
|
113 |
* <td>{@link java.util.Queue#offer offer(e)}</td>
|
jaroslav@597
|
114 |
* <td>{@link #offerLast offerLast(e)}</td>
|
jaroslav@597
|
115 |
* </tr>
|
jaroslav@597
|
116 |
* <tr>
|
jaroslav@597
|
117 |
* <td>{@link java.util.Queue#remove remove()}</td>
|
jaroslav@597
|
118 |
* <td>{@link #removeFirst removeFirst()}</td>
|
jaroslav@597
|
119 |
* </tr>
|
jaroslav@597
|
120 |
* <tr>
|
jaroslav@597
|
121 |
* <td>{@link java.util.Queue#poll poll()}</td>
|
jaroslav@597
|
122 |
* <td>{@link #pollFirst pollFirst()}</td>
|
jaroslav@597
|
123 |
* </tr>
|
jaroslav@597
|
124 |
* <tr>
|
jaroslav@597
|
125 |
* <td>{@link java.util.Queue#element element()}</td>
|
jaroslav@597
|
126 |
* <td>{@link #getFirst getFirst()}</td>
|
jaroslav@597
|
127 |
* </tr>
|
jaroslav@597
|
128 |
* <tr>
|
jaroslav@597
|
129 |
* <td>{@link java.util.Queue#peek peek()}</td>
|
jaroslav@597
|
130 |
* <td>{@link #peek peekFirst()}</td>
|
jaroslav@597
|
131 |
* </tr>
|
jaroslav@597
|
132 |
* </table>
|
jaroslav@597
|
133 |
*
|
jaroslav@597
|
134 |
* <p>Deques can also be used as LIFO (Last-In-First-Out) stacks. This
|
jaroslav@597
|
135 |
* interface should be used in preference to the legacy {@link Stack} class.
|
jaroslav@597
|
136 |
* When a deque is used as a stack, elements are pushed and popped from the
|
jaroslav@597
|
137 |
* beginning of the deque. Stack methods are precisely equivalent to
|
jaroslav@597
|
138 |
* <tt>Deque</tt> methods as indicated in the table below:
|
jaroslav@597
|
139 |
*
|
jaroslav@597
|
140 |
* <p>
|
jaroslav@597
|
141 |
* <table BORDER CELLPADDING=3 CELLSPACING=1>
|
jaroslav@597
|
142 |
* <tr>
|
jaroslav@597
|
143 |
* <td ALIGN=CENTER> <b>Stack Method</b></td>
|
jaroslav@597
|
144 |
* <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>
|
jaroslav@597
|
145 |
* </tr>
|
jaroslav@597
|
146 |
* <tr>
|
jaroslav@597
|
147 |
* <td>{@link #push push(e)}</td>
|
jaroslav@597
|
148 |
* <td>{@link #addFirst addFirst(e)}</td>
|
jaroslav@597
|
149 |
* </tr>
|
jaroslav@597
|
150 |
* <tr>
|
jaroslav@597
|
151 |
* <td>{@link #pop pop()}</td>
|
jaroslav@597
|
152 |
* <td>{@link #removeFirst removeFirst()}</td>
|
jaroslav@597
|
153 |
* </tr>
|
jaroslav@597
|
154 |
* <tr>
|
jaroslav@597
|
155 |
* <td>{@link #peek peek()}</td>
|
jaroslav@597
|
156 |
* <td>{@link #peekFirst peekFirst()}</td>
|
jaroslav@597
|
157 |
* </tr>
|
jaroslav@597
|
158 |
* </table>
|
jaroslav@597
|
159 |
*
|
jaroslav@597
|
160 |
* <p>Note that the {@link #peek peek} method works equally well when
|
jaroslav@597
|
161 |
* a deque is used as a queue or a stack; in either case, elements are
|
jaroslav@597
|
162 |
* drawn from the beginning of the deque.
|
jaroslav@597
|
163 |
*
|
jaroslav@597
|
164 |
* <p>This interface provides two methods to remove interior
|
jaroslav@597
|
165 |
* elements, {@link #removeFirstOccurrence removeFirstOccurrence} and
|
jaroslav@597
|
166 |
* {@link #removeLastOccurrence removeLastOccurrence}.
|
jaroslav@597
|
167 |
*
|
jaroslav@597
|
168 |
* <p>Unlike the {@link List} interface, this interface does not
|
jaroslav@597
|
169 |
* provide support for indexed access to elements.
|
jaroslav@597
|
170 |
*
|
jaroslav@597
|
171 |
* <p>While <tt>Deque</tt> implementations are not strictly required
|
jaroslav@597
|
172 |
* to prohibit the insertion of null elements, they are strongly
|
jaroslav@597
|
173 |
* encouraged to do so. Users of any <tt>Deque</tt> implementations
|
jaroslav@597
|
174 |
* that do allow null elements are strongly encouraged <i>not</i> to
|
jaroslav@597
|
175 |
* take advantage of the ability to insert nulls. This is so because
|
jaroslav@597
|
176 |
* <tt>null</tt> is used as a special return value by various methods
|
jaroslav@597
|
177 |
* to indicated that the deque is empty.
|
jaroslav@597
|
178 |
*
|
jaroslav@597
|
179 |
* <p><tt>Deque</tt> implementations generally do not define
|
jaroslav@597
|
180 |
* element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>
|
jaroslav@597
|
181 |
* methods, but instead inherit the identity-based versions from class
|
jaroslav@597
|
182 |
* <tt>Object</tt>.
|
jaroslav@597
|
183 |
*
|
jaroslav@597
|
184 |
* <p>This interface is a member of the <a
|
jaroslav@597
|
185 |
* href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
|
jaroslav@597
|
186 |
* Framework</a>.
|
jaroslav@597
|
187 |
*
|
jaroslav@597
|
188 |
* @author Doug Lea
|
jaroslav@597
|
189 |
* @author Josh Bloch
|
jaroslav@597
|
190 |
* @since 1.6
|
jaroslav@597
|
191 |
* @param <E> the type of elements held in this collection
|
jaroslav@597
|
192 |
*/
|
jaroslav@597
|
193 |
|
jaroslav@597
|
194 |
public interface Deque<E> extends Queue<E> {
|
jaroslav@597
|
195 |
/**
|
jaroslav@597
|
196 |
* Inserts the specified element at the front of this deque if it is
|
jaroslav@597
|
197 |
* possible to do so immediately without violating capacity restrictions.
|
jaroslav@597
|
198 |
* When using a capacity-restricted deque, it is generally preferable to
|
jaroslav@597
|
199 |
* use method {@link #offerFirst}.
|
jaroslav@597
|
200 |
*
|
jaroslav@597
|
201 |
* @param e the element to add
|
jaroslav@597
|
202 |
* @throws IllegalStateException if the element cannot be added at this
|
jaroslav@597
|
203 |
* time due to capacity restrictions
|
jaroslav@597
|
204 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
205 |
* prevents it from being added to this deque
|
jaroslav@597
|
206 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
207 |
* deque does not permit null elements
|
jaroslav@597
|
208 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
209 |
* element prevents it from being added to this deque
|
jaroslav@597
|
210 |
*/
|
jaroslav@597
|
211 |
void addFirst(E e);
|
jaroslav@597
|
212 |
|
jaroslav@597
|
213 |
/**
|
jaroslav@597
|
214 |
* Inserts the specified element at the end of this deque if it is
|
jaroslav@597
|
215 |
* possible to do so immediately without violating capacity restrictions.
|
jaroslav@597
|
216 |
* When using a capacity-restricted deque, it is generally preferable to
|
jaroslav@597
|
217 |
* use method {@link #offerLast}.
|
jaroslav@597
|
218 |
*
|
jaroslav@597
|
219 |
* <p>This method is equivalent to {@link #add}.
|
jaroslav@597
|
220 |
*
|
jaroslav@597
|
221 |
* @param e the element to add
|
jaroslav@597
|
222 |
* @throws IllegalStateException if the element cannot be added at this
|
jaroslav@597
|
223 |
* time due to capacity restrictions
|
jaroslav@597
|
224 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
225 |
* prevents it from being added to this deque
|
jaroslav@597
|
226 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
227 |
* deque does not permit null elements
|
jaroslav@597
|
228 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
229 |
* element prevents it from being added to this deque
|
jaroslav@597
|
230 |
*/
|
jaroslav@597
|
231 |
void addLast(E e);
|
jaroslav@597
|
232 |
|
jaroslav@597
|
233 |
/**
|
jaroslav@597
|
234 |
* Inserts the specified element at the front of this deque unless it would
|
jaroslav@597
|
235 |
* violate capacity restrictions. When using a capacity-restricted deque,
|
jaroslav@597
|
236 |
* this method is generally preferable to the {@link #addFirst} method,
|
jaroslav@597
|
237 |
* which can fail to insert an element only by throwing an exception.
|
jaroslav@597
|
238 |
*
|
jaroslav@597
|
239 |
* @param e the element to add
|
jaroslav@597
|
240 |
* @return <tt>true</tt> if the element was added to this deque, else
|
jaroslav@597
|
241 |
* <tt>false</tt>
|
jaroslav@597
|
242 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
243 |
* prevents it from being added to this deque
|
jaroslav@597
|
244 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
245 |
* deque does not permit null elements
|
jaroslav@597
|
246 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
247 |
* element prevents it from being added to this deque
|
jaroslav@597
|
248 |
*/
|
jaroslav@597
|
249 |
boolean offerFirst(E e);
|
jaroslav@597
|
250 |
|
jaroslav@597
|
251 |
/**
|
jaroslav@597
|
252 |
* Inserts the specified element at the end of this deque unless it would
|
jaroslav@597
|
253 |
* violate capacity restrictions. When using a capacity-restricted deque,
|
jaroslav@597
|
254 |
* this method is generally preferable to the {@link #addLast} method,
|
jaroslav@597
|
255 |
* which can fail to insert an element only by throwing an exception.
|
jaroslav@597
|
256 |
*
|
jaroslav@597
|
257 |
* @param e the element to add
|
jaroslav@597
|
258 |
* @return <tt>true</tt> if the element was added to this deque, else
|
jaroslav@597
|
259 |
* <tt>false</tt>
|
jaroslav@597
|
260 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
261 |
* prevents it from being added to this deque
|
jaroslav@597
|
262 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
263 |
* deque does not permit null elements
|
jaroslav@597
|
264 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
265 |
* element prevents it from being added to this deque
|
jaroslav@597
|
266 |
*/
|
jaroslav@597
|
267 |
boolean offerLast(E e);
|
jaroslav@597
|
268 |
|
jaroslav@597
|
269 |
/**
|
jaroslav@597
|
270 |
* Retrieves and removes the first element of this deque. This method
|
jaroslav@597
|
271 |
* differs from {@link #pollFirst pollFirst} only in that it throws an
|
jaroslav@597
|
272 |
* exception if this deque is empty.
|
jaroslav@597
|
273 |
*
|
jaroslav@597
|
274 |
* @return the head of this deque
|
jaroslav@597
|
275 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
276 |
*/
|
jaroslav@597
|
277 |
E removeFirst();
|
jaroslav@597
|
278 |
|
jaroslav@597
|
279 |
/**
|
jaroslav@597
|
280 |
* Retrieves and removes the last element of this deque. This method
|
jaroslav@597
|
281 |
* differs from {@link #pollLast pollLast} only in that it throws an
|
jaroslav@597
|
282 |
* exception if this deque is empty.
|
jaroslav@597
|
283 |
*
|
jaroslav@597
|
284 |
* @return the tail of this deque
|
jaroslav@597
|
285 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
286 |
*/
|
jaroslav@597
|
287 |
E removeLast();
|
jaroslav@597
|
288 |
|
jaroslav@597
|
289 |
/**
|
jaroslav@597
|
290 |
* Retrieves and removes the first element of this deque,
|
jaroslav@597
|
291 |
* or returns <tt>null</tt> if this deque is empty.
|
jaroslav@597
|
292 |
*
|
jaroslav@597
|
293 |
* @return the head of this deque, or <tt>null</tt> if this deque is empty
|
jaroslav@597
|
294 |
*/
|
jaroslav@597
|
295 |
E pollFirst();
|
jaroslav@597
|
296 |
|
jaroslav@597
|
297 |
/**
|
jaroslav@597
|
298 |
* Retrieves and removes the last element of this deque,
|
jaroslav@597
|
299 |
* or returns <tt>null</tt> if this deque is empty.
|
jaroslav@597
|
300 |
*
|
jaroslav@597
|
301 |
* @return the tail of this deque, or <tt>null</tt> if this deque is empty
|
jaroslav@597
|
302 |
*/
|
jaroslav@597
|
303 |
E pollLast();
|
jaroslav@597
|
304 |
|
jaroslav@597
|
305 |
/**
|
jaroslav@597
|
306 |
* Retrieves, but does not remove, the first element of this deque.
|
jaroslav@597
|
307 |
*
|
jaroslav@597
|
308 |
* This method differs from {@link #peekFirst peekFirst} only in that it
|
jaroslav@597
|
309 |
* throws an exception if this deque is empty.
|
jaroslav@597
|
310 |
*
|
jaroslav@597
|
311 |
* @return the head of this deque
|
jaroslav@597
|
312 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
313 |
*/
|
jaroslav@597
|
314 |
E getFirst();
|
jaroslav@597
|
315 |
|
jaroslav@597
|
316 |
/**
|
jaroslav@597
|
317 |
* Retrieves, but does not remove, the last element of this deque.
|
jaroslav@597
|
318 |
* This method differs from {@link #peekLast peekLast} only in that it
|
jaroslav@597
|
319 |
* throws an exception if this deque is empty.
|
jaroslav@597
|
320 |
*
|
jaroslav@597
|
321 |
* @return the tail of this deque
|
jaroslav@597
|
322 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
323 |
*/
|
jaroslav@597
|
324 |
E getLast();
|
jaroslav@597
|
325 |
|
jaroslav@597
|
326 |
/**
|
jaroslav@597
|
327 |
* Retrieves, but does not remove, the first element of this deque,
|
jaroslav@597
|
328 |
* or returns <tt>null</tt> if this deque is empty.
|
jaroslav@597
|
329 |
*
|
jaroslav@597
|
330 |
* @return the head of this deque, or <tt>null</tt> if this deque is empty
|
jaroslav@597
|
331 |
*/
|
jaroslav@597
|
332 |
E peekFirst();
|
jaroslav@597
|
333 |
|
jaroslav@597
|
334 |
/**
|
jaroslav@597
|
335 |
* Retrieves, but does not remove, the last element of this deque,
|
jaroslav@597
|
336 |
* or returns <tt>null</tt> if this deque is empty.
|
jaroslav@597
|
337 |
*
|
jaroslav@597
|
338 |
* @return the tail of this deque, or <tt>null</tt> if this deque is empty
|
jaroslav@597
|
339 |
*/
|
jaroslav@597
|
340 |
E peekLast();
|
jaroslav@597
|
341 |
|
jaroslav@597
|
342 |
/**
|
jaroslav@597
|
343 |
* Removes the first occurrence of the specified element from this deque.
|
jaroslav@597
|
344 |
* If the deque does not contain the element, it is unchanged.
|
jaroslav@597
|
345 |
* More formally, removes the first element <tt>e</tt> such that
|
jaroslav@597
|
346 |
* <tt>(o==null ? e==null : o.equals(e))</tt>
|
jaroslav@597
|
347 |
* (if such an element exists).
|
jaroslav@597
|
348 |
* Returns <tt>true</tt> if this deque contained the specified element
|
jaroslav@597
|
349 |
* (or equivalently, if this deque changed as a result of the call).
|
jaroslav@597
|
350 |
*
|
jaroslav@597
|
351 |
* @param o element to be removed from this deque, if present
|
jaroslav@597
|
352 |
* @return <tt>true</tt> if an element was removed as a result of this call
|
jaroslav@597
|
353 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
354 |
* is incompatible with this deque
|
jaroslav@597
|
355 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
356 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
357 |
* deque does not permit null elements
|
jaroslav@597
|
358 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
359 |
*/
|
jaroslav@597
|
360 |
boolean removeFirstOccurrence(Object o);
|
jaroslav@597
|
361 |
|
jaroslav@597
|
362 |
/**
|
jaroslav@597
|
363 |
* Removes the last occurrence of the specified element from this deque.
|
jaroslav@597
|
364 |
* If the deque does not contain the element, it is unchanged.
|
jaroslav@597
|
365 |
* More formally, removes the last element <tt>e</tt> such that
|
jaroslav@597
|
366 |
* <tt>(o==null ? e==null : o.equals(e))</tt>
|
jaroslav@597
|
367 |
* (if such an element exists).
|
jaroslav@597
|
368 |
* Returns <tt>true</tt> if this deque contained the specified element
|
jaroslav@597
|
369 |
* (or equivalently, if this deque changed as a result of the call).
|
jaroslav@597
|
370 |
*
|
jaroslav@597
|
371 |
* @param o element to be removed from this deque, if present
|
jaroslav@597
|
372 |
* @return <tt>true</tt> if an element was removed as a result of this call
|
jaroslav@597
|
373 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
374 |
* is incompatible with this deque
|
jaroslav@597
|
375 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
376 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
377 |
* deque does not permit null elements
|
jaroslav@597
|
378 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
379 |
*/
|
jaroslav@597
|
380 |
boolean removeLastOccurrence(Object o);
|
jaroslav@597
|
381 |
|
jaroslav@597
|
382 |
// *** Queue methods ***
|
jaroslav@597
|
383 |
|
jaroslav@597
|
384 |
/**
|
jaroslav@597
|
385 |
* Inserts the specified element into the queue represented by this deque
|
jaroslav@597
|
386 |
* (in other words, at the tail of this deque) if it is possible to do so
|
jaroslav@597
|
387 |
* immediately without violating capacity restrictions, returning
|
jaroslav@597
|
388 |
* <tt>true</tt> upon success and throwing an
|
jaroslav@597
|
389 |
* <tt>IllegalStateException</tt> if no space is currently available.
|
jaroslav@597
|
390 |
* When using a capacity-restricted deque, it is generally preferable to
|
jaroslav@597
|
391 |
* use {@link #offer(Object) offer}.
|
jaroslav@597
|
392 |
*
|
jaroslav@597
|
393 |
* <p>This method is equivalent to {@link #addLast}.
|
jaroslav@597
|
394 |
*
|
jaroslav@597
|
395 |
* @param e the element to add
|
jaroslav@597
|
396 |
* @return <tt>true</tt> (as specified by {@link Collection#add})
|
jaroslav@597
|
397 |
* @throws IllegalStateException if the element cannot be added at this
|
jaroslav@597
|
398 |
* time due to capacity restrictions
|
jaroslav@597
|
399 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
400 |
* prevents it from being added to this deque
|
jaroslav@597
|
401 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
402 |
* deque does not permit null elements
|
jaroslav@597
|
403 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
404 |
* element prevents it from being added to this deque
|
jaroslav@597
|
405 |
*/
|
jaroslav@597
|
406 |
boolean add(E e);
|
jaroslav@597
|
407 |
|
jaroslav@597
|
408 |
/**
|
jaroslav@597
|
409 |
* Inserts the specified element into the queue represented by this deque
|
jaroslav@597
|
410 |
* (in other words, at the tail of this deque) if it is possible to do so
|
jaroslav@597
|
411 |
* immediately without violating capacity restrictions, returning
|
jaroslav@597
|
412 |
* <tt>true</tt> upon success and <tt>false</tt> if no space is currently
|
jaroslav@597
|
413 |
* available. When using a capacity-restricted deque, this method is
|
jaroslav@597
|
414 |
* generally preferable to the {@link #add} method, which can fail to
|
jaroslav@597
|
415 |
* insert an element only by throwing an exception.
|
jaroslav@597
|
416 |
*
|
jaroslav@597
|
417 |
* <p>This method is equivalent to {@link #offerLast}.
|
jaroslav@597
|
418 |
*
|
jaroslav@597
|
419 |
* @param e the element to add
|
jaroslav@597
|
420 |
* @return <tt>true</tt> if the element was added to this deque, else
|
jaroslav@597
|
421 |
* <tt>false</tt>
|
jaroslav@597
|
422 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
423 |
* prevents it from being added to this deque
|
jaroslav@597
|
424 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
425 |
* deque does not permit null elements
|
jaroslav@597
|
426 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
427 |
* element prevents it from being added to this deque
|
jaroslav@597
|
428 |
*/
|
jaroslav@597
|
429 |
boolean offer(E e);
|
jaroslav@597
|
430 |
|
jaroslav@597
|
431 |
/**
|
jaroslav@597
|
432 |
* Retrieves and removes the head of the queue represented by this deque
|
jaroslav@597
|
433 |
* (in other words, the first element of this deque).
|
jaroslav@597
|
434 |
* This method differs from {@link #poll poll} only in that it throws an
|
jaroslav@597
|
435 |
* exception if this deque is empty.
|
jaroslav@597
|
436 |
*
|
jaroslav@597
|
437 |
* <p>This method is equivalent to {@link #removeFirst()}.
|
jaroslav@597
|
438 |
*
|
jaroslav@597
|
439 |
* @return the head of the queue represented by this deque
|
jaroslav@597
|
440 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
441 |
*/
|
jaroslav@597
|
442 |
E remove();
|
jaroslav@597
|
443 |
|
jaroslav@597
|
444 |
/**
|
jaroslav@597
|
445 |
* Retrieves and removes the head of the queue represented by this deque
|
jaroslav@597
|
446 |
* (in other words, the first element of this deque), or returns
|
jaroslav@597
|
447 |
* <tt>null</tt> if this deque is empty.
|
jaroslav@597
|
448 |
*
|
jaroslav@597
|
449 |
* <p>This method is equivalent to {@link #pollFirst()}.
|
jaroslav@597
|
450 |
*
|
jaroslav@597
|
451 |
* @return the first element of this deque, or <tt>null</tt> if
|
jaroslav@597
|
452 |
* this deque is empty
|
jaroslav@597
|
453 |
*/
|
jaroslav@597
|
454 |
E poll();
|
jaroslav@597
|
455 |
|
jaroslav@597
|
456 |
/**
|
jaroslav@597
|
457 |
* Retrieves, but does not remove, the head of the queue represented by
|
jaroslav@597
|
458 |
* this deque (in other words, the first element of this deque).
|
jaroslav@597
|
459 |
* This method differs from {@link #peek peek} only in that it throws an
|
jaroslav@597
|
460 |
* exception if this deque is empty.
|
jaroslav@597
|
461 |
*
|
jaroslav@597
|
462 |
* <p>This method is equivalent to {@link #getFirst()}.
|
jaroslav@597
|
463 |
*
|
jaroslav@597
|
464 |
* @return the head of the queue represented by this deque
|
jaroslav@597
|
465 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
466 |
*/
|
jaroslav@597
|
467 |
E element();
|
jaroslav@597
|
468 |
|
jaroslav@597
|
469 |
/**
|
jaroslav@597
|
470 |
* Retrieves, but does not remove, the head of the queue represented by
|
jaroslav@597
|
471 |
* this deque (in other words, the first element of this deque), or
|
jaroslav@597
|
472 |
* returns <tt>null</tt> if this deque is empty.
|
jaroslav@597
|
473 |
*
|
jaroslav@597
|
474 |
* <p>This method is equivalent to {@link #peekFirst()}.
|
jaroslav@597
|
475 |
*
|
jaroslav@597
|
476 |
* @return the head of the queue represented by this deque, or
|
jaroslav@597
|
477 |
* <tt>null</tt> if this deque is empty
|
jaroslav@597
|
478 |
*/
|
jaroslav@597
|
479 |
E peek();
|
jaroslav@597
|
480 |
|
jaroslav@597
|
481 |
|
jaroslav@597
|
482 |
// *** Stack methods ***
|
jaroslav@597
|
483 |
|
jaroslav@597
|
484 |
/**
|
jaroslav@597
|
485 |
* Pushes an element onto the stack represented by this deque (in other
|
jaroslav@597
|
486 |
* words, at the head of this deque) if it is possible to do so
|
jaroslav@597
|
487 |
* immediately without violating capacity restrictions, returning
|
jaroslav@597
|
488 |
* <tt>true</tt> upon success and throwing an
|
jaroslav@597
|
489 |
* <tt>IllegalStateException</tt> if no space is currently available.
|
jaroslav@597
|
490 |
*
|
jaroslav@597
|
491 |
* <p>This method is equivalent to {@link #addFirst}.
|
jaroslav@597
|
492 |
*
|
jaroslav@597
|
493 |
* @param e the element to push
|
jaroslav@597
|
494 |
* @throws IllegalStateException if the element cannot be added at this
|
jaroslav@597
|
495 |
* time due to capacity restrictions
|
jaroslav@597
|
496 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
497 |
* prevents it from being added to this deque
|
jaroslav@597
|
498 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
499 |
* deque does not permit null elements
|
jaroslav@597
|
500 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@597
|
501 |
* element prevents it from being added to this deque
|
jaroslav@597
|
502 |
*/
|
jaroslav@597
|
503 |
void push(E e);
|
jaroslav@597
|
504 |
|
jaroslav@597
|
505 |
/**
|
jaroslav@597
|
506 |
* Pops an element from the stack represented by this deque. In other
|
jaroslav@597
|
507 |
* words, removes and returns the first element of this deque.
|
jaroslav@597
|
508 |
*
|
jaroslav@597
|
509 |
* <p>This method is equivalent to {@link #removeFirst()}.
|
jaroslav@597
|
510 |
*
|
jaroslav@597
|
511 |
* @return the element at the front of this deque (which is the top
|
jaroslav@597
|
512 |
* of the stack represented by this deque)
|
jaroslav@597
|
513 |
* @throws NoSuchElementException if this deque is empty
|
jaroslav@597
|
514 |
*/
|
jaroslav@597
|
515 |
E pop();
|
jaroslav@597
|
516 |
|
jaroslav@597
|
517 |
|
jaroslav@597
|
518 |
// *** Collection methods ***
|
jaroslav@597
|
519 |
|
jaroslav@597
|
520 |
/**
|
jaroslav@597
|
521 |
* Removes the first occurrence of the specified element from this deque.
|
jaroslav@597
|
522 |
* If the deque does not contain the element, it is unchanged.
|
jaroslav@597
|
523 |
* More formally, removes the first element <tt>e</tt> such that
|
jaroslav@597
|
524 |
* <tt>(o==null ? e==null : o.equals(e))</tt>
|
jaroslav@597
|
525 |
* (if such an element exists).
|
jaroslav@597
|
526 |
* Returns <tt>true</tt> if this deque contained the specified element
|
jaroslav@597
|
527 |
* (or equivalently, if this deque changed as a result of the call).
|
jaroslav@597
|
528 |
*
|
jaroslav@597
|
529 |
* <p>This method is equivalent to {@link #removeFirstOccurrence}.
|
jaroslav@597
|
530 |
*
|
jaroslav@597
|
531 |
* @param o element to be removed from this deque, if present
|
jaroslav@597
|
532 |
* @return <tt>true</tt> if an element was removed as a result of this call
|
jaroslav@597
|
533 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@597
|
534 |
* is incompatible with this deque
|
jaroslav@597
|
535 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
536 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
537 |
* deque does not permit null elements
|
jaroslav@597
|
538 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
539 |
*/
|
jaroslav@597
|
540 |
boolean remove(Object o);
|
jaroslav@597
|
541 |
|
jaroslav@597
|
542 |
/**
|
jaroslav@597
|
543 |
* Returns <tt>true</tt> if this deque contains the specified element.
|
jaroslav@597
|
544 |
* More formally, returns <tt>true</tt> if and only if this deque contains
|
jaroslav@597
|
545 |
* at least one element <tt>e</tt> such that
|
jaroslav@597
|
546 |
* <tt>(o==null ? e==null : o.equals(e))</tt>.
|
jaroslav@597
|
547 |
*
|
jaroslav@597
|
548 |
* @param o element whose presence in this deque is to be tested
|
jaroslav@597
|
549 |
* @return <tt>true</tt> if this deque contains the specified element
|
jaroslav@597
|
550 |
* @throws ClassCastException if the type of the specified element
|
jaroslav@597
|
551 |
* is incompatible with this deque
|
jaroslav@597
|
552 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
553 |
* @throws NullPointerException if the specified element is null and this
|
jaroslav@597
|
554 |
* deque does not permit null elements
|
jaroslav@597
|
555 |
* (<a href="Collection.html#optional-restrictions">optional</a>)
|
jaroslav@597
|
556 |
*/
|
jaroslav@597
|
557 |
boolean contains(Object o);
|
jaroslav@597
|
558 |
|
jaroslav@597
|
559 |
/**
|
jaroslav@597
|
560 |
* Returns the number of elements in this deque.
|
jaroslav@597
|
561 |
*
|
jaroslav@597
|
562 |
* @return the number of elements in this deque
|
jaroslav@597
|
563 |
*/
|
jaroslav@597
|
564 |
public int size();
|
jaroslav@597
|
565 |
|
jaroslav@597
|
566 |
/**
|
jaroslav@597
|
567 |
* Returns an iterator over the elements in this deque in proper sequence.
|
jaroslav@597
|
568 |
* The elements will be returned in order from first (head) to last (tail).
|
jaroslav@597
|
569 |
*
|
jaroslav@597
|
570 |
* @return an iterator over the elements in this deque in proper sequence
|
jaroslav@597
|
571 |
*/
|
jaroslav@597
|
572 |
Iterator<E> iterator();
|
jaroslav@597
|
573 |
|
jaroslav@597
|
574 |
/**
|
jaroslav@597
|
575 |
* Returns an iterator over the elements in this deque in reverse
|
jaroslav@597
|
576 |
* sequential order. The elements will be returned in order from
|
jaroslav@597
|
577 |
* last (tail) to first (head).
|
jaroslav@597
|
578 |
*
|
jaroslav@597
|
579 |
* @return an iterator over the elements in this deque in reverse
|
jaroslav@597
|
580 |
* sequence
|
jaroslav@597
|
581 |
*/
|
jaroslav@597
|
582 |
Iterator<E> descendingIterator();
|
jaroslav@597
|
583 |
|
jaroslav@597
|
584 |
}
|