7 |
|
import java.io.Serializable; |
8 |
|
import java.util.function.Consumer; |
9 |
|
import java.util.stream.Stream; |
10 |
– |
import java.util.stream.Streams; |
10 |
|
|
11 |
|
/** |
12 |
|
* Resizable-array implementation of the {@link Deque} interface. Array |
845 |
|
elements[i] = s.readObject(); |
846 |
|
} |
847 |
|
|
848 |
< |
Spliterator<E> spliterator() { |
848 |
> |
public Spliterator<E> spliterator() { |
849 |
|
return new DeqSpliterator<E>(this, -1, -1); |
850 |
|
} |
851 |
|
|
853 |
– |
public Stream<E> stream() { |
854 |
– |
return Streams.stream(spliterator()); |
855 |
– |
} |
856 |
– |
|
857 |
– |
public Stream<E> parallelStream() { |
858 |
– |
return Streams.parallelStream(spliterator()); |
859 |
– |
} |
860 |
– |
|
852 |
|
static final class DeqSpliterator<E> implements Spliterator<E> { |
853 |
|
private final ArrayDeque<E> deq; |
854 |
|
private int fence; // -1 until first use |
870 |
|
return t; |
871 |
|
} |
872 |
|
|
873 |
< |
public DeqSpliterator<E> trySplit() { |
873 |
> |
public Spliterator<E> trySplit() { |
874 |
|
int t = getFence(), h = index, n = deq.elements.length; |
875 |
|
if (h != t && ((h + 1) & (n - 1)) != t) { |
876 |
|
if (h > t) |
881 |
|
return null; |
882 |
|
} |
883 |
|
|
884 |
< |
public void forEach(Consumer<? super E> consumer) { |
884 |
> |
public void forEachRemaining(Consumer<? super E> consumer) { |
885 |
|
if (consumer == null) |
886 |
|
throw new NullPointerException(); |
887 |
|
Object[] a = deq.elements; |