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 |
612 |
|
} |
613 |
|
} |
614 |
|
|
615 |
+ |
/** |
616 |
+ |
* This class is nearly a mirror-image of DeqIterator, using tail |
617 |
+ |
* instead of head for initial cursor, and head instead of tail |
618 |
+ |
* for fence. |
619 |
+ |
*/ |
620 |
|
private class DescendingIterator implements Iterator<E> { |
617 |
– |
/* |
618 |
– |
* This class is nearly a mirror-image of DeqIterator, using |
619 |
– |
* tail instead of head for initial cursor, and head instead of |
620 |
– |
* tail for fence. |
621 |
– |
*/ |
621 |
|
private int cursor = tail; |
622 |
|
private int fence = head; |
623 |
|
private int lastRet = -1; |
810 |
|
/** |
811 |
|
* Saves this deque to a stream (that is, serializes it). |
812 |
|
* |
813 |
+ |
* @param s the stream |
814 |
+ |
* @throws java.io.IOException if an I/O error occurs |
815 |
|
* @serialData The current size ({@code int}) of the deque, |
816 |
|
* followed by all of its elements (each an object reference) in |
817 |
|
* first-to-last order. |
831 |
|
|
832 |
|
/** |
833 |
|
* Reconstitutes this deque from a stream (that is, deserializes it). |
834 |
+ |
* @param s the stream |
835 |
+ |
* @throws ClassNotFoundException if the class of a serialized object |
836 |
+ |
* could not be found |
837 |
+ |
* @throws java.io.IOException if an I/O error occurs |
838 |
|
*/ |
839 |
|
private void readObject(java.io.ObjectInputStream s) |
840 |
|
throws java.io.IOException, ClassNotFoundException { |
851 |
|
elements[i] = s.readObject(); |
852 |
|
} |
853 |
|
|
854 |
< |
Spliterator<E> spliterator() { |
854 |
> |
public Spliterator<E> spliterator() { |
855 |
|
return new DeqSpliterator<E>(this, -1, -1); |
856 |
|
} |
857 |
|
|
853 |
– |
public Stream<E> stream() { |
854 |
– |
return Streams.stream(spliterator()); |
855 |
– |
} |
856 |
– |
|
857 |
– |
public Stream<E> parallelStream() { |
858 |
– |
return Streams.parallelStream(spliterator()); |
859 |
– |
} |
860 |
– |
|
858 |
|
static final class DeqSpliterator<E> implements Spliterator<E> { |
859 |
|
private final ArrayDeque<E> deq; |
860 |
|
private int fence; // -1 until first use |
876 |
|
return t; |
877 |
|
} |
878 |
|
|
879 |
< |
public DeqSpliterator<E> trySplit() { |
879 |
> |
public Spliterator<E> trySplit() { |
880 |
|
int t = getFence(), h = index, n = deq.elements.length; |
881 |
|
if (h != t && ((h + 1) & (n - 1)) != t) { |
882 |
|
if (h > t) |
887 |
|
return null; |
888 |
|
} |
889 |
|
|
890 |
< |
public void forEach(Consumer<? super E> consumer) { |
890 |
> |
public void forEachRemaining(Consumer<? super E> consumer) { |
891 |
|
if (consumer == null) |
892 |
|
throw new NullPointerException(); |
893 |
|
Object[] a = deq.elements; |