296 |
|
} |
297 |
|
} |
298 |
|
|
299 |
+ |
public int drainTo(Collection<? super E> c) { |
300 |
+ |
if (c == null) |
301 |
+ |
throw new NullPointerException(); |
302 |
+ |
if (c == this) |
303 |
+ |
throw new IllegalArgumentException(); |
304 |
+ |
lock.lock(); |
305 |
+ |
try { |
306 |
+ |
int n = 0; |
307 |
+ |
E e; |
308 |
+ |
while ( (e = q.poll()) != null) { |
309 |
+ |
c.add(e); |
310 |
+ |
++n; |
311 |
+ |
} |
312 |
+ |
return n; |
313 |
+ |
} finally { |
314 |
+ |
lock.unlock(); |
315 |
+ |
} |
316 |
+ |
} |
317 |
+ |
|
318 |
+ |
public int drainTo(Collection<? super E> c, int maxElements) { |
319 |
+ |
if (c == null) |
320 |
+ |
throw new NullPointerException(); |
321 |
+ |
if (c == this) |
322 |
+ |
throw new IllegalArgumentException(); |
323 |
+ |
if (maxElements <= 0) |
324 |
+ |
return 0; |
325 |
+ |
lock.lock(); |
326 |
+ |
try { |
327 |
+ |
int n = 0; |
328 |
+ |
E e; |
329 |
+ |
while (n < maxElements && (e = q.poll()) != null) { |
330 |
+ |
c.add(e); |
331 |
+ |
++n; |
332 |
+ |
} |
333 |
+ |
return n; |
334 |
+ |
} finally { |
335 |
+ |
lock.unlock(); |
336 |
+ |
} |
337 |
+ |
} |
338 |
+ |
|
339 |
|
/** |
340 |
|
* Atomically removes all of the elements from this delay queue. |
341 |
|
* The queue will be empty after this call returns. |