jaroslav@1890
|
1 |
/*
|
jaroslav@1890
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
jaroslav@1890
|
3 |
*
|
jaroslav@1890
|
4 |
* This code is free software; you can redistribute it and/or modify it
|
jaroslav@1890
|
5 |
* under the terms of the GNU General Public License version 2 only, as
|
jaroslav@1890
|
6 |
* published by the Free Software Foundation. Oracle designates this
|
jaroslav@1890
|
7 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@1890
|
8 |
* by Oracle in the LICENSE file that accompanied this code.
|
jaroslav@1890
|
9 |
*
|
jaroslav@1890
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
jaroslav@1890
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
jaroslav@1890
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
jaroslav@1890
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that
|
jaroslav@1890
|
14 |
* accompanied this code).
|
jaroslav@1890
|
15 |
*
|
jaroslav@1890
|
16 |
* You should have received a copy of the GNU General Public License version
|
jaroslav@1890
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
jaroslav@1890
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
jaroslav@1890
|
19 |
*
|
jaroslav@1890
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
jaroslav@1890
|
21 |
* or visit www.oracle.com if you need additional information or have any
|
jaroslav@1890
|
22 |
* questions.
|
jaroslav@1890
|
23 |
*/
|
jaroslav@1890
|
24 |
|
jaroslav@1890
|
25 |
/*
|
jaroslav@1890
|
26 |
* This file is available under and governed by the GNU General Public
|
jaroslav@1890
|
27 |
* License version 2 only, as published by the Free Software Foundation.
|
jaroslav@1890
|
28 |
* However, the following notice accompanied the original version of this
|
jaroslav@1890
|
29 |
* file:
|
jaroslav@1890
|
30 |
*
|
jaroslav@1890
|
31 |
* Written by Doug Lea with assistance from members of JCP JSR-166
|
jaroslav@1890
|
32 |
* Expert Group and released to the public domain, as explained at
|
jaroslav@1890
|
33 |
* http://creativecommons.org/publicdomain/zero/1.0/
|
jaroslav@1890
|
34 |
*/
|
jaroslav@1890
|
35 |
|
jaroslav@1890
|
36 |
package java.util.concurrent;
|
jaroslav@1890
|
37 |
|
jaroslav@1890
|
38 |
import java.util.Collection;
|
jaroslav@1890
|
39 |
import java.util.Queue;
|
jaroslav@1890
|
40 |
|
jaroslav@1890
|
41 |
/**
|
jaroslav@1890
|
42 |
* A {@link java.util.Queue} that additionally supports operations
|
jaroslav@1890
|
43 |
* that wait for the queue to become non-empty when retrieving an
|
jaroslav@1890
|
44 |
* element, and wait for space to become available in the queue when
|
jaroslav@1890
|
45 |
* storing an element.
|
jaroslav@1890
|
46 |
*
|
jaroslav@1890
|
47 |
* <p><tt>BlockingQueue</tt> methods come in four forms, with different ways
|
jaroslav@1890
|
48 |
* of handling operations that cannot be satisfied immediately, but may be
|
jaroslav@1890
|
49 |
* satisfied at some point in the future:
|
jaroslav@1890
|
50 |
* one throws an exception, the second returns a special value (either
|
jaroslav@1890
|
51 |
* <tt>null</tt> or <tt>false</tt>, depending on the operation), the third
|
jaroslav@1890
|
52 |
* blocks the current thread indefinitely until the operation can succeed,
|
jaroslav@1890
|
53 |
* and the fourth blocks for only a given maximum time limit before giving
|
jaroslav@1890
|
54 |
* up. These methods are summarized in the following table:
|
jaroslav@1890
|
55 |
*
|
jaroslav@1890
|
56 |
* <p>
|
jaroslav@1890
|
57 |
* <table BORDER CELLPADDING=3 CELLSPACING=1>
|
jaroslav@1890
|
58 |
* <tr>
|
jaroslav@1890
|
59 |
* <td></td>
|
jaroslav@1890
|
60 |
* <td ALIGN=CENTER><em>Throws exception</em></td>
|
jaroslav@1890
|
61 |
* <td ALIGN=CENTER><em>Special value</em></td>
|
jaroslav@1890
|
62 |
* <td ALIGN=CENTER><em>Blocks</em></td>
|
jaroslav@1890
|
63 |
* <td ALIGN=CENTER><em>Times out</em></td>
|
jaroslav@1890
|
64 |
* </tr>
|
jaroslav@1890
|
65 |
* <tr>
|
jaroslav@1890
|
66 |
* <td><b>Insert</b></td>
|
jaroslav@1890
|
67 |
* <td>{@link #add add(e)}</td>
|
jaroslav@1890
|
68 |
* <td>{@link #offer offer(e)}</td>
|
jaroslav@1890
|
69 |
* <td>{@link #put put(e)}</td>
|
jaroslav@1890
|
70 |
* <td>{@link #offer(Object, long, TimeUnit) offer(e, time, unit)}</td>
|
jaroslav@1890
|
71 |
* </tr>
|
jaroslav@1890
|
72 |
* <tr>
|
jaroslav@1890
|
73 |
* <td><b>Remove</b></td>
|
jaroslav@1890
|
74 |
* <td>{@link #remove remove()}</td>
|
jaroslav@1890
|
75 |
* <td>{@link #poll poll()}</td>
|
jaroslav@1890
|
76 |
* <td>{@link #take take()}</td>
|
jaroslav@1890
|
77 |
* <td>{@link #poll(long, TimeUnit) poll(time, unit)}</td>
|
jaroslav@1890
|
78 |
* </tr>
|
jaroslav@1890
|
79 |
* <tr>
|
jaroslav@1890
|
80 |
* <td><b>Examine</b></td>
|
jaroslav@1890
|
81 |
* <td>{@link #element element()}</td>
|
jaroslav@1890
|
82 |
* <td>{@link #peek peek()}</td>
|
jaroslav@1890
|
83 |
* <td><em>not applicable</em></td>
|
jaroslav@1890
|
84 |
* <td><em>not applicable</em></td>
|
jaroslav@1890
|
85 |
* </tr>
|
jaroslav@1890
|
86 |
* </table>
|
jaroslav@1890
|
87 |
*
|
jaroslav@1890
|
88 |
* <p>A <tt>BlockingQueue</tt> does not accept <tt>null</tt> elements.
|
jaroslav@1890
|
89 |
* Implementations throw <tt>NullPointerException</tt> on attempts
|
jaroslav@1890
|
90 |
* to <tt>add</tt>, <tt>put</tt> or <tt>offer</tt> a <tt>null</tt>. A
|
jaroslav@1890
|
91 |
* <tt>null</tt> is used as a sentinel value to indicate failure of
|
jaroslav@1890
|
92 |
* <tt>poll</tt> operations.
|
jaroslav@1890
|
93 |
*
|
jaroslav@1890
|
94 |
* <p>A <tt>BlockingQueue</tt> may be capacity bounded. At any given
|
jaroslav@1890
|
95 |
* time it may have a <tt>remainingCapacity</tt> beyond which no
|
jaroslav@1890
|
96 |
* additional elements can be <tt>put</tt> without blocking.
|
jaroslav@1890
|
97 |
* A <tt>BlockingQueue</tt> without any intrinsic capacity constraints always
|
jaroslav@1890
|
98 |
* reports a remaining capacity of <tt>Integer.MAX_VALUE</tt>.
|
jaroslav@1890
|
99 |
*
|
jaroslav@1890
|
100 |
* <p> <tt>BlockingQueue</tt> implementations are designed to be used
|
jaroslav@1890
|
101 |
* primarily for producer-consumer queues, but additionally support
|
jaroslav@1890
|
102 |
* the {@link java.util.Collection} interface. So, for example, it is
|
jaroslav@1890
|
103 |
* possible to remove an arbitrary element from a queue using
|
jaroslav@1890
|
104 |
* <tt>remove(x)</tt>. However, such operations are in general
|
jaroslav@1890
|
105 |
* <em>not</em> performed very efficiently, and are intended for only
|
jaroslav@1890
|
106 |
* occasional use, such as when a queued message is cancelled.
|
jaroslav@1890
|
107 |
*
|
jaroslav@1890
|
108 |
* <p> <tt>BlockingQueue</tt> implementations are thread-safe. All
|
jaroslav@1890
|
109 |
* queuing methods achieve their effects atomically using internal
|
jaroslav@1890
|
110 |
* locks or other forms of concurrency control. However, the
|
jaroslav@1890
|
111 |
* <em>bulk</em> Collection operations <tt>addAll</tt>,
|
jaroslav@1890
|
112 |
* <tt>containsAll</tt>, <tt>retainAll</tt> and <tt>removeAll</tt> are
|
jaroslav@1890
|
113 |
* <em>not</em> necessarily performed atomically unless specified
|
jaroslav@1890
|
114 |
* otherwise in an implementation. So it is possible, for example, for
|
jaroslav@1890
|
115 |
* <tt>addAll(c)</tt> to fail (throwing an exception) after adding
|
jaroslav@1890
|
116 |
* only some of the elements in <tt>c</tt>.
|
jaroslav@1890
|
117 |
*
|
jaroslav@1890
|
118 |
* <p>A <tt>BlockingQueue</tt> does <em>not</em> intrinsically support
|
jaroslav@1890
|
119 |
* any kind of "close" or "shutdown" operation to
|
jaroslav@1890
|
120 |
* indicate that no more items will be added. The needs and usage of
|
jaroslav@1890
|
121 |
* such features tend to be implementation-dependent. For example, a
|
jaroslav@1890
|
122 |
* common tactic is for producers to insert special
|
jaroslav@1890
|
123 |
* <em>end-of-stream</em> or <em>poison</em> objects, that are
|
jaroslav@1890
|
124 |
* interpreted accordingly when taken by consumers.
|
jaroslav@1890
|
125 |
*
|
jaroslav@1890
|
126 |
* <p>
|
jaroslav@1890
|
127 |
* Usage example, based on a typical producer-consumer scenario.
|
jaroslav@1890
|
128 |
* Note that a <tt>BlockingQueue</tt> can safely be used with multiple
|
jaroslav@1890
|
129 |
* producers and multiple consumers.
|
jaroslav@1890
|
130 |
* <pre>
|
jaroslav@1890
|
131 |
* class Producer implements Runnable {
|
jaroslav@1890
|
132 |
* private final BlockingQueue queue;
|
jaroslav@1890
|
133 |
* Producer(BlockingQueue q) { queue = q; }
|
jaroslav@1890
|
134 |
* public void run() {
|
jaroslav@1890
|
135 |
* try {
|
jaroslav@1890
|
136 |
* while (true) { queue.put(produce()); }
|
jaroslav@1890
|
137 |
* } catch (InterruptedException ex) { ... handle ...}
|
jaroslav@1890
|
138 |
* }
|
jaroslav@1890
|
139 |
* Object produce() { ... }
|
jaroslav@1890
|
140 |
* }
|
jaroslav@1890
|
141 |
*
|
jaroslav@1890
|
142 |
* class Consumer implements Runnable {
|
jaroslav@1890
|
143 |
* private final BlockingQueue queue;
|
jaroslav@1890
|
144 |
* Consumer(BlockingQueue q) { queue = q; }
|
jaroslav@1890
|
145 |
* public void run() {
|
jaroslav@1890
|
146 |
* try {
|
jaroslav@1890
|
147 |
* while (true) { consume(queue.take()); }
|
jaroslav@1890
|
148 |
* } catch (InterruptedException ex) { ... handle ...}
|
jaroslav@1890
|
149 |
* }
|
jaroslav@1890
|
150 |
* void consume(Object x) { ... }
|
jaroslav@1890
|
151 |
* }
|
jaroslav@1890
|
152 |
*
|
jaroslav@1890
|
153 |
* class Setup {
|
jaroslav@1890
|
154 |
* void main() {
|
jaroslav@1890
|
155 |
* BlockingQueue q = new SomeQueueImplementation();
|
jaroslav@1890
|
156 |
* Producer p = new Producer(q);
|
jaroslav@1890
|
157 |
* Consumer c1 = new Consumer(q);
|
jaroslav@1890
|
158 |
* Consumer c2 = new Consumer(q);
|
jaroslav@1890
|
159 |
* new Thread(p).start();
|
jaroslav@1890
|
160 |
* new Thread(c1).start();
|
jaroslav@1890
|
161 |
* new Thread(c2).start();
|
jaroslav@1890
|
162 |
* }
|
jaroslav@1890
|
163 |
* }
|
jaroslav@1890
|
164 |
* </pre>
|
jaroslav@1890
|
165 |
*
|
jaroslav@1890
|
166 |
* <p>Memory consistency effects: As with other concurrent
|
jaroslav@1890
|
167 |
* collections, actions in a thread prior to placing an object into a
|
jaroslav@1890
|
168 |
* {@code BlockingQueue}
|
jaroslav@1890
|
169 |
* <a href="package-summary.html#MemoryVisibility"><i>happen-before</i></a>
|
jaroslav@1890
|
170 |
* actions subsequent to the access or removal of that element from
|
jaroslav@1890
|
171 |
* the {@code BlockingQueue} in another thread.
|
jaroslav@1890
|
172 |
*
|
jaroslav@1890
|
173 |
* <p>This interface is a member of the
|
jaroslav@1890
|
174 |
* <a href="{@docRoot}/../technotes/guides/collections/index.html">
|
jaroslav@1890
|
175 |
* Java Collections Framework</a>.
|
jaroslav@1890
|
176 |
*
|
jaroslav@1890
|
177 |
* @since 1.5
|
jaroslav@1890
|
178 |
* @author Doug Lea
|
jaroslav@1890
|
179 |
* @param <E> the type of elements held in this collection
|
jaroslav@1890
|
180 |
*/
|
jaroslav@1890
|
181 |
public interface BlockingQueue<E> extends Queue<E> {
|
jaroslav@1890
|
182 |
/**
|
jaroslav@1890
|
183 |
* Inserts the specified element into this queue if it is possible to do
|
jaroslav@1890
|
184 |
* so immediately without violating capacity restrictions, returning
|
jaroslav@1890
|
185 |
* <tt>true</tt> upon success and throwing an
|
jaroslav@1890
|
186 |
* <tt>IllegalStateException</tt> if no space is currently available.
|
jaroslav@1890
|
187 |
* When using a capacity-restricted queue, it is generally preferable to
|
jaroslav@1890
|
188 |
* use {@link #offer(Object) offer}.
|
jaroslav@1890
|
189 |
*
|
jaroslav@1890
|
190 |
* @param e the element to add
|
jaroslav@1890
|
191 |
* @return <tt>true</tt> (as specified by {@link Collection#add})
|
jaroslav@1890
|
192 |
* @throws IllegalStateException if the element cannot be added at this
|
jaroslav@1890
|
193 |
* time due to capacity restrictions
|
jaroslav@1890
|
194 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@1890
|
195 |
* prevents it from being added to this queue
|
jaroslav@1890
|
196 |
* @throws NullPointerException if the specified element is null
|
jaroslav@1890
|
197 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@1890
|
198 |
* element prevents it from being added to this queue
|
jaroslav@1890
|
199 |
*/
|
jaroslav@1890
|
200 |
boolean add(E e);
|
jaroslav@1890
|
201 |
|
jaroslav@1890
|
202 |
/**
|
jaroslav@1890
|
203 |
* Inserts the specified element into this queue if it is possible to do
|
jaroslav@1890
|
204 |
* so immediately without violating capacity restrictions, returning
|
jaroslav@1890
|
205 |
* <tt>true</tt> upon success and <tt>false</tt> if no space is currently
|
jaroslav@1890
|
206 |
* available. When using a capacity-restricted queue, this method is
|
jaroslav@1890
|
207 |
* generally preferable to {@link #add}, which can fail to insert an
|
jaroslav@1890
|
208 |
* element only by throwing an exception.
|
jaroslav@1890
|
209 |
*
|
jaroslav@1890
|
210 |
* @param e the element to add
|
jaroslav@1890
|
211 |
* @return <tt>true</tt> if the element was added to this queue, else
|
jaroslav@1890
|
212 |
* <tt>false</tt>
|
jaroslav@1890
|
213 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@1890
|
214 |
* prevents it from being added to this queue
|
jaroslav@1890
|
215 |
* @throws NullPointerException if the specified element is null
|
jaroslav@1890
|
216 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@1890
|
217 |
* element prevents it from being added to this queue
|
jaroslav@1890
|
218 |
*/
|
jaroslav@1890
|
219 |
boolean offer(E e);
|
jaroslav@1890
|
220 |
|
jaroslav@1890
|
221 |
/**
|
jaroslav@1890
|
222 |
* Inserts the specified element into this queue, waiting if necessary
|
jaroslav@1890
|
223 |
* for space to become available.
|
jaroslav@1890
|
224 |
*
|
jaroslav@1890
|
225 |
* @param e the element to add
|
jaroslav@1890
|
226 |
* @throws InterruptedException if interrupted while waiting
|
jaroslav@1890
|
227 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@1890
|
228 |
* prevents it from being added to this queue
|
jaroslav@1890
|
229 |
* @throws NullPointerException if the specified element is null
|
jaroslav@1890
|
230 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@1890
|
231 |
* element prevents it from being added to this queue
|
jaroslav@1890
|
232 |
*/
|
jaroslav@1890
|
233 |
void put(E e) throws InterruptedException;
|
jaroslav@1890
|
234 |
|
jaroslav@1890
|
235 |
/**
|
jaroslav@1890
|
236 |
* Inserts the specified element into this queue, waiting up to the
|
jaroslav@1890
|
237 |
* specified wait time if necessary for space to become available.
|
jaroslav@1890
|
238 |
*
|
jaroslav@1890
|
239 |
* @param e the element to add
|
jaroslav@1890
|
240 |
* @param timeout how long to wait before giving up, in units of
|
jaroslav@1890
|
241 |
* <tt>unit</tt>
|
jaroslav@1890
|
242 |
* @param unit a <tt>TimeUnit</tt> determining how to interpret the
|
jaroslav@1890
|
243 |
* <tt>timeout</tt> parameter
|
jaroslav@1890
|
244 |
* @return <tt>true</tt> if successful, or <tt>false</tt> if
|
jaroslav@1890
|
245 |
* the specified waiting time elapses before space is available
|
jaroslav@1890
|
246 |
* @throws InterruptedException if interrupted while waiting
|
jaroslav@1890
|
247 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@1890
|
248 |
* prevents it from being added to this queue
|
jaroslav@1890
|
249 |
* @throws NullPointerException if the specified element is null
|
jaroslav@1890
|
250 |
* @throws IllegalArgumentException if some property of the specified
|
jaroslav@1890
|
251 |
* element prevents it from being added to this queue
|
jaroslav@1890
|
252 |
*/
|
jaroslav@1890
|
253 |
boolean offer(E e, long timeout, TimeUnit unit)
|
jaroslav@1890
|
254 |
throws InterruptedException;
|
jaroslav@1890
|
255 |
|
jaroslav@1890
|
256 |
/**
|
jaroslav@1890
|
257 |
* Retrieves and removes the head of this queue, waiting if necessary
|
jaroslav@1890
|
258 |
* until an element becomes available.
|
jaroslav@1890
|
259 |
*
|
jaroslav@1890
|
260 |
* @return the head of this queue
|
jaroslav@1890
|
261 |
* @throws InterruptedException if interrupted while waiting
|
jaroslav@1890
|
262 |
*/
|
jaroslav@1890
|
263 |
E take() throws InterruptedException;
|
jaroslav@1890
|
264 |
|
jaroslav@1890
|
265 |
/**
|
jaroslav@1890
|
266 |
* Retrieves and removes the head of this queue, waiting up to the
|
jaroslav@1890
|
267 |
* specified wait time if necessary for an element to become available.
|
jaroslav@1890
|
268 |
*
|
jaroslav@1890
|
269 |
* @param timeout how long to wait before giving up, in units of
|
jaroslav@1890
|
270 |
* <tt>unit</tt>
|
jaroslav@1890
|
271 |
* @param unit a <tt>TimeUnit</tt> determining how to interpret the
|
jaroslav@1890
|
272 |
* <tt>timeout</tt> parameter
|
jaroslav@1890
|
273 |
* @return the head of this queue, or <tt>null</tt> if the
|
jaroslav@1890
|
274 |
* specified waiting time elapses before an element is available
|
jaroslav@1890
|
275 |
* @throws InterruptedException if interrupted while waiting
|
jaroslav@1890
|
276 |
*/
|
jaroslav@1890
|
277 |
E poll(long timeout, TimeUnit unit)
|
jaroslav@1890
|
278 |
throws InterruptedException;
|
jaroslav@1890
|
279 |
|
jaroslav@1890
|
280 |
/**
|
jaroslav@1890
|
281 |
* Returns the number of additional elements that this queue can ideally
|
jaroslav@1890
|
282 |
* (in the absence of memory or resource constraints) accept without
|
jaroslav@1890
|
283 |
* blocking, or <tt>Integer.MAX_VALUE</tt> if there is no intrinsic
|
jaroslav@1890
|
284 |
* limit.
|
jaroslav@1890
|
285 |
*
|
jaroslav@1890
|
286 |
* <p>Note that you <em>cannot</em> always tell if an attempt to insert
|
jaroslav@1890
|
287 |
* an element will succeed by inspecting <tt>remainingCapacity</tt>
|
jaroslav@1890
|
288 |
* because it may be the case that another thread is about to
|
jaroslav@1890
|
289 |
* insert or remove an element.
|
jaroslav@1890
|
290 |
*
|
jaroslav@1890
|
291 |
* @return the remaining capacity
|
jaroslav@1890
|
292 |
*/
|
jaroslav@1890
|
293 |
int remainingCapacity();
|
jaroslav@1890
|
294 |
|
jaroslav@1890
|
295 |
/**
|
jaroslav@1890
|
296 |
* Removes a single instance of the specified element from this queue,
|
jaroslav@1890
|
297 |
* if it is present. More formally, removes an element <tt>e</tt> such
|
jaroslav@1890
|
298 |
* that <tt>o.equals(e)</tt>, if this queue contains one or more such
|
jaroslav@1890
|
299 |
* elements.
|
jaroslav@1890
|
300 |
* Returns <tt>true</tt> if this queue contained the specified element
|
jaroslav@1890
|
301 |
* (or equivalently, if this queue changed as a result of the call).
|
jaroslav@1890
|
302 |
*
|
jaroslav@1890
|
303 |
* @param o element to be removed from this queue, if present
|
jaroslav@1890
|
304 |
* @return <tt>true</tt> if this queue changed as a result of the call
|
jaroslav@1890
|
305 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@1890
|
306 |
* is incompatible with this queue
|
jaroslav@1890
|
307 |
* (<a href="../Collection.html#optional-restrictions">optional</a>)
|
jaroslav@1890
|
308 |
* @throws NullPointerException if the specified element is null
|
jaroslav@1890
|
309 |
* (<a href="../Collection.html#optional-restrictions">optional</a>)
|
jaroslav@1890
|
310 |
*/
|
jaroslav@1890
|
311 |
boolean remove(Object o);
|
jaroslav@1890
|
312 |
|
jaroslav@1890
|
313 |
/**
|
jaroslav@1890
|
314 |
* Returns <tt>true</tt> if this queue contains the specified element.
|
jaroslav@1890
|
315 |
* More formally, returns <tt>true</tt> if and only if this queue contains
|
jaroslav@1890
|
316 |
* at least one element <tt>e</tt> such that <tt>o.equals(e)</tt>.
|
jaroslav@1890
|
317 |
*
|
jaroslav@1890
|
318 |
* @param o object to be checked for containment in this queue
|
jaroslav@1890
|
319 |
* @return <tt>true</tt> if this queue contains the specified element
|
jaroslav@1890
|
320 |
* @throws ClassCastException if the class of the specified element
|
jaroslav@1890
|
321 |
* is incompatible with this queue
|
jaroslav@1890
|
322 |
* (<a href="../Collection.html#optional-restrictions">optional</a>)
|
jaroslav@1890
|
323 |
* @throws NullPointerException if the specified element is null
|
jaroslav@1890
|
324 |
* (<a href="../Collection.html#optional-restrictions">optional</a>)
|
jaroslav@1890
|
325 |
*/
|
jaroslav@1890
|
326 |
public boolean contains(Object o);
|
jaroslav@1890
|
327 |
|
jaroslav@1890
|
328 |
/**
|
jaroslav@1890
|
329 |
* Removes all available elements from this queue and adds them
|
jaroslav@1890
|
330 |
* to the given collection. This operation may be more
|
jaroslav@1890
|
331 |
* efficient than repeatedly polling this queue. A failure
|
jaroslav@1890
|
332 |
* encountered while attempting to add elements to
|
jaroslav@1890
|
333 |
* collection <tt>c</tt> may result in elements being in neither,
|
jaroslav@1890
|
334 |
* either or both collections when the associated exception is
|
jaroslav@1890
|
335 |
* thrown. Attempts to drain a queue to itself result in
|
jaroslav@1890
|
336 |
* <tt>IllegalArgumentException</tt>. Further, the behavior of
|
jaroslav@1890
|
337 |
* this operation is undefined if the specified collection is
|
jaroslav@1890
|
338 |
* modified while the operation is in progress.
|
jaroslav@1890
|
339 |
*
|
jaroslav@1890
|
340 |
* @param c the collection to transfer elements into
|
jaroslav@1890
|
341 |
* @return the number of elements transferred
|
jaroslav@1890
|
342 |
* @throws UnsupportedOperationException if addition of elements
|
jaroslav@1890
|
343 |
* is not supported by the specified collection
|
jaroslav@1890
|
344 |
* @throws ClassCastException if the class of an element of this queue
|
jaroslav@1890
|
345 |
* prevents it from being added to the specified collection
|
jaroslav@1890
|
346 |
* @throws NullPointerException if the specified collection is null
|
jaroslav@1890
|
347 |
* @throws IllegalArgumentException if the specified collection is this
|
jaroslav@1890
|
348 |
* queue, or some property of an element of this queue prevents
|
jaroslav@1890
|
349 |
* it from being added to the specified collection
|
jaroslav@1890
|
350 |
*/
|
jaroslav@1890
|
351 |
int drainTo(Collection<? super E> c);
|
jaroslav@1890
|
352 |
|
jaroslav@1890
|
353 |
/**
|
jaroslav@1890
|
354 |
* Removes at most the given number of available elements from
|
jaroslav@1890
|
355 |
* this queue and adds them to the given collection. A failure
|
jaroslav@1890
|
356 |
* encountered while attempting to add elements to
|
jaroslav@1890
|
357 |
* collection <tt>c</tt> may result in elements being in neither,
|
jaroslav@1890
|
358 |
* either or both collections when the associated exception is
|
jaroslav@1890
|
359 |
* thrown. Attempts to drain a queue to itself result in
|
jaroslav@1890
|
360 |
* <tt>IllegalArgumentException</tt>. Further, the behavior of
|
jaroslav@1890
|
361 |
* this operation is undefined if the specified collection is
|
jaroslav@1890
|
362 |
* modified while the operation is in progress.
|
jaroslav@1890
|
363 |
*
|
jaroslav@1890
|
364 |
* @param c the collection to transfer elements into
|
jaroslav@1890
|
365 |
* @param maxElements the maximum number of elements to transfer
|
jaroslav@1890
|
366 |
* @return the number of elements transferred
|
jaroslav@1890
|
367 |
* @throws UnsupportedOperationException if addition of elements
|
jaroslav@1890
|
368 |
* is not supported by the specified collection
|
jaroslav@1890
|
369 |
* @throws ClassCastException if the class of an element of this queue
|
jaroslav@1890
|
370 |
* prevents it from being added to the specified collection
|
jaroslav@1890
|
371 |
* @throws NullPointerException if the specified collection is null
|
jaroslav@1890
|
372 |
* @throws IllegalArgumentException if the specified collection is this
|
jaroslav@1890
|
373 |
* queue, or some property of an element of this queue prevents
|
jaroslav@1890
|
374 |
* it from being added to the specified collection
|
jaroslav@1890
|
375 |
*/
|
jaroslav@1890
|
376 |
int drainTo(Collection<? super E> c, int maxElements);
|
jaroslav@1890
|
377 |
}
|