985 |
|
LTQSpliterator() {} |
986 |
|
|
987 |
|
public Spliterator<E> trySplit() { |
988 |
< |
Node p; |
989 |
< |
int b = batch; |
990 |
< |
int n = (b <= 0) ? 1 : (b >= MAX_BATCH) ? MAX_BATCH : b + 1; |
991 |
< |
if (!exhausted && |
992 |
< |
((p = current) != null || (p = firstDataNode()) != null) && |
993 |
< |
p.next != null) { |
994 |
< |
Object[] a = new Object[n]; |
995 |
< |
int i = 0; |
996 |
< |
do { |
997 |
< |
final Object item = p.item; |
998 |
< |
if (p.isData) { |
999 |
< |
if (item != null) |
1000 |
< |
a[i++] = item; |
1001 |
< |
} |
1002 |
< |
else if (item == null) { |
1003 |
< |
p = null; |
1004 |
< |
break; |
1005 |
< |
} |
1006 |
< |
if (p == (p = p.next)) |
1007 |
< |
p = head; |
1008 |
< |
} while (p != null && i < n); |
1009 |
< |
if ((current = p) == null) |
1010 |
< |
exhausted = true; |
1011 |
< |
if (i > 0) { |
1012 |
< |
batch = i; |
1013 |
< |
return Spliterators.spliterator |
1014 |
< |
(a, 0, i, (Spliterator.ORDERED | |
1015 |
< |
Spliterator.NONNULL | |
1016 |
< |
Spliterator.CONCURRENT)); |
988 |
> |
Node p, q; |
989 |
> |
if ((p = current()) == null || (q = p.next) == null) |
990 |
> |
return null; |
991 |
> |
int i = 0, n = batch = Math.min(batch + 1, MAX_BATCH); |
992 |
> |
Object[] a = null; |
993 |
> |
do { |
994 |
> |
final Object item = p.item; |
995 |
> |
if (p.isData) { |
996 |
> |
if (item != null) |
997 |
> |
((a != null) ? a : (a = new Object[n]))[i++] = item; |
998 |
> |
} else if (item == null) { |
999 |
> |
p = null; |
1000 |
> |
break; |
1001 |
|
} |
1002 |
< |
} |
1003 |
< |
return null; |
1002 |
> |
if (p == (p = q)) p = firstDataNode(); |
1003 |
> |
} while (p != null && (q = p.next) != null && i < n); |
1004 |
> |
setCurrent(p); |
1005 |
> |
return (i == 0) ? null : |
1006 |
> |
Spliterators.spliterator(a, 0, i, (Spliterator.ORDERED | |
1007 |
> |
Spliterator.NONNULL | |
1008 |
> |
Spliterator.CONCURRENT)); |
1009 |
|
} |
1010 |
|
|
1011 |
|
@SuppressWarnings("unchecked") |
1012 |
|
public void forEachRemaining(Consumer<? super E> action) { |
1013 |
|
Objects.requireNonNull(action); |
1014 |
|
Node p; |
1015 |
< |
if (!exhausted && |
1027 |
< |
((p = current) != null || (p = head) != null)) { |
1015 |
> |
if ((p = current()) != null) { |
1016 |
|
current = null; |
1017 |
|
exhausted = true; |
1018 |
|
do { |
1019 |
|
final Object item = p.item; |
1020 |
|
if (p.isData) { |
1021 |
|
if (item != null) |
1022 |
< |
action.accept((E)item); |
1022 |
> |
action.accept((E) item); |
1023 |
|
} |
1024 |
|
else if (item == null) |
1025 |
|
break; |
1033 |
|
public boolean tryAdvance(Consumer<? super E> action) { |
1034 |
|
Objects.requireNonNull(action); |
1035 |
|
Node p; |
1036 |
< |
if (!exhausted && |
1037 |
< |
((p = current) != null || (p = head) != null)) { |
1050 |
< |
Object item; |
1036 |
> |
if ((p = current()) != null) { |
1037 |
> |
E e = null; |
1038 |
|
do { |
1039 |
< |
if (p.isData) |
1040 |
< |
item = p.item; |
1041 |
< |
else { |
1042 |
< |
item = null; |
1043 |
< |
if (p.item == null) { |
1044 |
< |
p = null; |
1039 |
> |
final Object item = p.item; |
1040 |
> |
final boolean isData = p.isData; |
1041 |
> |
if (p == (p = p.next)) |
1042 |
> |
p = head; |
1043 |
> |
if (isData) { |
1044 |
> |
if (item != null) { |
1045 |
> |
e = (E) item; |
1046 |
|
break; |
1047 |
|
} |
1048 |
|
} |
1049 |
< |
if (p == (p = p.next)) |
1050 |
< |
p = head; |
1051 |
< |
} while (item == null && p != null); |
1052 |
< |
if ((current = p) == null) |
1053 |
< |
exhausted = true; |
1054 |
< |
if (item != null) { |
1067 |
< |
action.accept((E)item); |
1049 |
> |
else if (item == null) |
1050 |
> |
p = null; |
1051 |
> |
} while (p != null); |
1052 |
> |
setCurrent(p); |
1053 |
> |
if (e != null) { |
1054 |
> |
action.accept(e); |
1055 |
|
return true; |
1056 |
|
} |
1057 |
|
} |
1058 |
|
return false; |
1059 |
|
} |
1060 |
|
|
1061 |
+ |
private void setCurrent(Node p) { |
1062 |
+ |
if ((current = p) == null) |
1063 |
+ |
exhausted = true; |
1064 |
+ |
} |
1065 |
+ |
|
1066 |
+ |
private Node current() { |
1067 |
+ |
Node p; |
1068 |
+ |
if ((p = current) == null && !exhausted) |
1069 |
+ |
setCurrent(p = firstDataNode()); |
1070 |
+ |
return p; |
1071 |
+ |
} |
1072 |
+ |
|
1073 |
|
public long estimateSize() { return Long.MAX_VALUE; } |
1074 |
|
|
1075 |
|
public int characteristics() { |