--- jsr166/src/main/java/util/ArrayDeque.java 2013/02/20 12:32:01 1.50 +++ jsr166/src/main/java/util/ArrayDeque.java 2013/07/18 18:21:22 1.57 @@ -7,7 +7,6 @@ package java.util; import java.io.Serializable; import java.util.function.Consumer; import java.util.stream.Stream; -import java.util.stream.Streams; /** * Resizable-array implementation of the {@link Deque} interface. Array @@ -19,16 +18,18 @@ import java.util.stream.Streams; * when used as a queue. * *

Most {@code ArrayDeque} operations run in amortized constant time. - * Exceptions include {@link #remove(Object) remove}, {@link - * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence - * removeLastOccurrence}, {@link #contains contains}, {@link #iterator - * iterator.remove()}, and the bulk operations, all of which run in linear - * time. + * Exceptions include + * {@link #remove(Object) remove}, + * {@link #removeFirstOccurrence removeFirstOccurrence}, + * {@link #removeLastOccurrence removeLastOccurrence}, + * {@link #contains contains}, + * {@link #iterator iterator.remove()}, + * and the bulk operations, all of which run in linear time. * - *

The iterators returned by this class's {@code iterator} method are - * fail-fast: If the deque is modified at any time after the iterator - * is created, in any way except through the iterator's own {@code remove} - * method, the iterator will generally throw a {@link + *

The iterators returned by this class's {@link #iterator() iterator} + * method are fail-fast: If the deque is modified at any time after + * the iterator is created, in any way except through the iterator's own + * {@code remove} method, the iterator will generally throw a {@link * ConcurrentModificationException}. Thus, in the face of concurrent * modification, the iterator fails quickly and cleanly, rather than risking * arbitrary, non-deterministic behavior at an undetermined time in the @@ -611,12 +612,12 @@ public class ArrayDeque extends Abstr } } + /** + * This class is nearly a mirror-image of DeqIterator, using tail + * instead of head for initial cursor, and head instead of tail + * for fence. + */ private class DescendingIterator implements Iterator { - /* - * This class is nearly a mirror-image of DeqIterator, using - * tail instead of head for initial cursor, and head instead of - * tail for fence. - */ private int cursor = tail; private int fence = head; private int lastRet = -1; @@ -809,6 +810,8 @@ public class ArrayDeque extends Abstr /** * Saves this deque to a stream (that is, serializes it). * + * @param s the stream + * @throws java.io.IOException if an I/O error occurs * @serialData The current size ({@code int}) of the deque, * followed by all of its elements (each an object reference) in * first-to-last order. @@ -828,6 +831,10 @@ public class ArrayDeque extends Abstr /** * Reconstitutes this deque from a stream (that is, deserializes it). + * @param s the stream + * @throws ClassNotFoundException if the class of a serialized object + * could not be found + * @throws java.io.IOException if an I/O error occurs */ private void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { @@ -844,18 +851,10 @@ public class ArrayDeque extends Abstr elements[i] = s.readObject(); } - Spliterator spliterator() { + public Spliterator spliterator() { return new DeqSpliterator(this, -1, -1); } - public Stream stream() { - return Streams.stream(spliterator()); - } - - public Stream parallelStream() { - return Streams.parallelStream(spliterator()); - } - static final class DeqSpliterator implements Spliterator { private final ArrayDeque deq; private int fence; // -1 until first use @@ -877,7 +876,7 @@ public class ArrayDeque extends Abstr return t; } - public DeqSpliterator trySplit() { + public Spliterator trySplit() { int t = getFence(), h = index, n = deq.elements.length; if (h != t && ((h + 1) & (n - 1)) != t) { if (h > t) @@ -888,7 +887,7 @@ public class ArrayDeque extends Abstr return null; } - public void forEach(Consumer consumer) { + public void forEachRemaining(Consumer consumer) { if (consumer == null) throw new NullPointerException(); Object[] a = deq.elements;