1373 |
|
} |
1374 |
|
|
1375 |
|
/** A customized variant of Spliterators.IteratorSpliterator */ |
1376 |
< |
static final class CLDSpliterator<E> implements Spliterator<E> { |
1376 |
> |
final class CLDSpliterator implements Spliterator<E> { |
1377 |
|
static final int MAX_BATCH = 1 << 25; // max batch array size; |
1378 |
– |
final ConcurrentLinkedDeque<E> queue; |
1378 |
|
Node<E> current; // current node; null until initialized |
1379 |
|
int batch; // batch size for splits |
1380 |
|
boolean exhausted; // true when no more nodes |
1382 |
– |
CLDSpliterator(ConcurrentLinkedDeque<E> queue) { |
1383 |
– |
this.queue = queue; |
1384 |
– |
} |
1381 |
|
|
1382 |
|
public Spliterator<E> trySplit() { |
1383 |
|
Node<E> p; |
1388 |
– |
final ConcurrentLinkedDeque<E> q = this.queue; |
1384 |
|
int b = batch; |
1385 |
|
int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1; |
1386 |
|
if (!exhausted && |
1387 |
< |
((p = current) != null || (p = q.first()) != null)) { |
1387 |
> |
((p = current) != null || (p = first()) != null)) { |
1388 |
|
if (p.item == null && p == (p = p.next)) |
1389 |
< |
current = p = q.first(); |
1389 |
> |
current = p = first(); |
1390 |
|
if (p != null && p.next != null) { |
1391 |
|
Object[] a = new Object[n]; |
1392 |
|
int i = 0; |
1394 |
|
if ((a[i] = p.item) != null) |
1395 |
|
++i; |
1396 |
|
if (p == (p = p.next)) |
1397 |
< |
p = q.first(); |
1397 |
> |
p = first(); |
1398 |
|
} while (p != null && i < n); |
1399 |
|
if ((current = p) == null) |
1400 |
|
exhausted = true; |
1413 |
|
public void forEachRemaining(Consumer<? super E> action) { |
1414 |
|
Node<E> p; |
1415 |
|
if (action == null) throw new NullPointerException(); |
1421 |
– |
final ConcurrentLinkedDeque<E> q = this.queue; |
1416 |
|
if (!exhausted && |
1417 |
< |
((p = current) != null || (p = q.first()) != null)) { |
1417 |
> |
((p = current) != null || (p = first()) != null)) { |
1418 |
|
exhausted = true; |
1419 |
|
do { |
1420 |
|
E e = p.item; |
1421 |
|
if (p == (p = p.next)) |
1422 |
< |
p = q.first(); |
1422 |
> |
p = first(); |
1423 |
|
if (e != null) |
1424 |
|
action.accept(e); |
1425 |
|
} while (p != null); |
1429 |
|
public boolean tryAdvance(Consumer<? super E> action) { |
1430 |
|
Node<E> p; |
1431 |
|
if (action == null) throw new NullPointerException(); |
1438 |
– |
final ConcurrentLinkedDeque<E> q = this.queue; |
1432 |
|
if (!exhausted && |
1433 |
< |
((p = current) != null || (p = q.first()) != null)) { |
1433 |
> |
((p = current) != null || (p = first()) != null)) { |
1434 |
|
E e; |
1435 |
|
do { |
1436 |
|
e = p.item; |
1437 |
|
if (p == (p = p.next)) |
1438 |
< |
p = q.first(); |
1438 |
> |
p = first(); |
1439 |
|
} while (e == null && p != null); |
1440 |
|
if ((current = p) == null) |
1441 |
|
exhausted = true; |
1472 |
|
* @since 1.8 |
1473 |
|
*/ |
1474 |
|
public Spliterator<E> spliterator() { |
1475 |
< |
return new CLDSpliterator<E>(this); |
1475 |
> |
return new CLDSpliterator(); |
1476 |
|
} |
1477 |
|
|
1478 |
|
/** |