15 |
|
import java.util.Iterator; |
16 |
|
import java.util.List; |
17 |
|
import java.util.NoSuchElementException; |
18 |
+ |
import java.util.Objects; |
19 |
|
import java.util.concurrent.atomic.AtomicLong; |
20 |
|
import java.util.concurrent.locks.Condition; |
21 |
|
import java.util.concurrent.locks.ReentrantLock; |
1184 |
|
} |
1185 |
|
|
1186 |
|
public int drainTo(Collection<? super Runnable> c, int maxElements) { |
1187 |
< |
if (c == null) |
1187 |
< |
throw new NullPointerException(); |
1187 |
> |
Objects.requireNonNull(c); |
1188 |
|
if (c == this) |
1189 |
|
throw new IllegalArgumentException(); |
1190 |
|
if (maxElements <= 0) |
1192 |
|
final ReentrantLock lock = this.lock; |
1193 |
|
lock.lock(); |
1194 |
|
try { |
1195 |
– |
RunnableScheduledFuture<?> first; |
1195 |
|
int n = 0; |
1196 |
< |
while (n < maxElements |
1197 |
< |
&& (first = queue[0]) != null |
1198 |
< |
&& first.getDelay(NANOSECONDS) <= 0) { |
1196 |
> |
for (RunnableScheduledFuture<?> first; |
1197 |
> |
n < maxElements |
1198 |
> |
&& (first = queue[0]) != null |
1199 |
> |
&& first.getDelay(NANOSECONDS) <= 0;) { |
1200 |
|
c.add(first); // In this order, in case add() throws. |
1201 |
|
finishPoll(first); |
1202 |
|
++n; |