11 |
|
import java.util.Collection; |
12 |
|
import java.util.Iterator; |
13 |
|
import java.util.NoSuchElementException; |
14 |
+ |
import java.util.Objects; |
15 |
|
import java.util.Spliterator; |
16 |
|
import java.util.Spliterators; |
17 |
|
import java.util.concurrent.locks.Condition; |
114 |
|
} |
115 |
|
|
116 |
|
/** |
116 |
– |
* Throws NullPointerException if argument is null. |
117 |
– |
* |
118 |
– |
* @param v the element |
119 |
– |
*/ |
120 |
– |
private static void checkNotNull(Object v) { |
121 |
– |
if (v == null) |
122 |
– |
throw new NullPointerException(); |
123 |
– |
} |
124 |
– |
|
125 |
– |
/** |
117 |
|
* Inserts element at current put position, advances, and signals. |
118 |
|
* Call only when holding lock. |
119 |
|
*/ |
239 |
|
try { |
240 |
|
int i = 0; |
241 |
|
try { |
242 |
< |
for (E e : c) { |
243 |
< |
checkNotNull(e); |
253 |
< |
items[i++] = e; |
254 |
< |
} |
242 |
> |
for (E e : c) |
243 |
> |
items[i++] = Objects.requireNonNull(e); |
244 |
|
} catch (ArrayIndexOutOfBoundsException ex) { |
245 |
|
throw new IllegalArgumentException(); |
246 |
|
} |
276 |
|
* @throws NullPointerException if the specified element is null |
277 |
|
*/ |
278 |
|
public boolean offer(E e) { |
279 |
< |
checkNotNull(e); |
279 |
> |
Objects.requireNonNull(e); |
280 |
|
final ReentrantLock lock = this.lock; |
281 |
|
lock.lock(); |
282 |
|
try { |
299 |
|
* @throws NullPointerException {@inheritDoc} |
300 |
|
*/ |
301 |
|
public void put(E e) throws InterruptedException { |
302 |
< |
checkNotNull(e); |
302 |
> |
Objects.requireNonNull(e); |
303 |
|
final ReentrantLock lock = this.lock; |
304 |
|
lock.lockInterruptibly(); |
305 |
|
try { |
322 |
|
public boolean offer(E e, long timeout, TimeUnit unit) |
323 |
|
throws InterruptedException { |
324 |
|
|
325 |
< |
checkNotNull(e); |
325 |
> |
Objects.requireNonNull(e); |
326 |
|
long nanos = unit.toNanos(timeout); |
327 |
|
final ReentrantLock lock = this.lock; |
328 |
|
lock.lockInterruptibly(); |
656 |
|
* @throws IllegalArgumentException {@inheritDoc} |
657 |
|
*/ |
658 |
|
public int drainTo(Collection<? super E> c, int maxElements) { |
659 |
< |
checkNotNull(c); |
659 |
> |
Objects.requireNonNull(c); |
660 |
|
if (c == this) |
661 |
|
throw new IllegalArgumentException(); |
662 |
|
if (maxElements <= 0) |