changeset 7521:8c3211b22686

- Consolidate array-based and iterator-based spliterators into java.util.Spliterators. - Update primitive array-based and iterator-based spliterators.
author psandoz
date Fri, 22 Feb 2013 18:53:32 +0100
parents c08707396c40
children 418a74c46029
files src/share/classes/java/io/BufferedReader.java src/share/classes/java/lang/CharSequence.java src/share/classes/java/nio/file/DirectoryStream.java src/share/classes/java/nio/file/Files.java src/share/classes/java/util/Arrays.java src/share/classes/java/util/BitSet.java src/share/classes/java/util/Collection.java src/share/classes/java/util/Collections.java src/share/classes/java/util/HashMap.java src/share/classes/java/util/LinkedHashSet.java src/share/classes/java/util/LinkedList.java src/share/classes/java/util/List.java src/share/classes/java/util/PrimitiveIterator.java src/share/classes/java/util/Set.java src/share/classes/java/util/SortedSet.java src/share/classes/java/util/Spliterators.java src/share/classes/java/util/concurrent/ArrayBlockingQueue.java src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java src/share/classes/java/util/concurrent/LinkedBlockingDeque.java src/share/classes/java/util/concurrent/LinkedBlockingQueue.java src/share/classes/java/util/concurrent/LinkedTransferQueue.java src/share/classes/java/util/concurrent/PriorityBlockingQueue.java src/share/classes/java/util/concurrent/SynchronousQueue.java src/share/classes/java/util/stream/DoublePipeline.java src/share/classes/java/util/stream/DoubleStream.java src/share/classes/java/util/stream/IntPipeline.java src/share/classes/java/util/stream/IntStream.java src/share/classes/java/util/stream/LongPipeline.java src/share/classes/java/util/stream/LongStream.java src/share/classes/java/util/stream/Nodes.java src/share/classes/java/util/stream/ReferencePipeline.java src/share/classes/java/util/stream/SpinedBuffer.java src/share/classes/java/util/stream/Spliterators.java src/share/classes/java/util/stream/Stream.java src/share/classes/java/util/stream/StreamSpliterators.java src/share/classes/java/util/stream/Streams.java test-ng/bootlib/java/util/stream/DoubleStreamTestData.java test-ng/bootlib/java/util/stream/DoubleStreamTestDataProvider.java test-ng/bootlib/java/util/stream/DoubleStreamTestScenario.java test-ng/bootlib/java/util/stream/IntStreamTestData.java test-ng/bootlib/java/util/stream/IntStreamTestDataProvider.java test-ng/bootlib/java/util/stream/IntStreamTestScenario.java test-ng/bootlib/java/util/stream/LambdaTestHelpers.java test-ng/bootlib/java/util/stream/LongStreamTestData.java test-ng/bootlib/java/util/stream/LongStreamTestDataProvider.java test-ng/bootlib/java/util/stream/LongStreamTestScenario.java test-ng/bootlib/java/util/stream/OpTestCase.java test-ng/bootlib/java/util/stream/StreamTestDataProvider.java test-ng/boottests/java/util/stream/DoubleNodeTest.java test-ng/boottests/java/util/stream/IntNodeTest.java test-ng/boottests/java/util/stream/LongNodeTest.java test-ng/boottests/java/util/stream/SpinedBufferTest.java test-ng/tests/org/openjdk/tests/java/lang/CharSequenceStreamTest.java test-ng/tests/org/openjdk/tests/java/util/BitsetStreamTest.java test-ng/tests/org/openjdk/tests/java/util/stream/CollectionAndMapModifyStreamTest.java test-ng/tests/org/openjdk/tests/java/util/stream/FindAnyOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/FindFirstOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/MatchOpTest.java test-ng/tests/org/openjdk/tests/java/util/stream/SortedOpTest.java test/java/util/stream/Stream/IntegerStreamTest.java test/java/util/stream/Streams/BasicTest.java
diffstat 64 files changed, 2063 insertions(+), 1840 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/io/BufferedReader.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/io/BufferedReader.java	Fri Feb 22 18:53:32 2013 +0100
@@ -29,6 +29,7 @@
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
 
@@ -583,6 +584,6 @@
                 }
             }
         };
-        return Streams.stream(Streams.spliteratorUnknownSize(iter, Spliterator.ORDERED));
+        return Streams.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED));
     }
 }
--- a/src/share/classes/java/lang/CharSequence.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/lang/CharSequence.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 package java.lang;
 
 import java.util.NoSuchElementException;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.IntConsumer;
 import java.util.stream.IntStream;
 import java.util.stream.Streams;
@@ -120,7 +122,7 @@
      * @return an Iterable of Character values from this sequence
      */
     public default IntStream chars() {
-        class CharIterator implements IntStream.IntIterator {
+        class CharIterator implements PrimitiveIterator.OfInt {
             int cur = 0;
 
             public boolean hasNext() {
@@ -141,7 +143,7 @@
             }
         }
 
-        return Streams.intStream(() -> Streams.intSpliterator(new CharIterator(), length(), Spliterator.ORDERED),
+        return Streams.intStream(() -> Spliterators.spliterator(new CharIterator(), length(), Spliterator.ORDERED),
                                  Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED);
     }
 
@@ -161,7 +163,7 @@
      * @return an Iterable of Unicode code points from this sequence
      */
     public default IntStream codePoints() {
-        class CodePointIterator implements IntStream.IntIterator {
+        class CodePointIterator implements PrimitiveIterator.OfInt {
             int cur = 0;
 
             @Override
@@ -188,7 +190,7 @@
             }
         }
 
-        return Streams.intStream(() -> Streams.intSpliteratorUnknownSize(new CodePointIterator(), Spliterator.ORDERED),
+        return Streams.intStream(() -> Spliterators.spliteratorUnknownSize(new CodePointIterator(), Spliterator.ORDERED),
                                  Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED);
     }
 }
--- a/src/share/classes/java/nio/file/DirectoryStream.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/nio/file/DirectoryStream.java	Fri Feb 22 18:53:32 2013 +0100
@@ -29,6 +29,7 @@
 import java.io.Closeable;
 import java.io.IOException;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
 
@@ -173,6 +174,6 @@
      * @since 1.8
      */
     default Stream<T> entries() {
-        return Streams.stream(Streams.spliteratorUnknownSize(iterator(), Spliterator.DISTINCT));
+        return Streams.stream(Spliterators.spliteratorUnknownSize(iterator(), Spliterator.DISTINCT));
     }
 }
--- a/src/share/classes/java/nio/file/Files.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/nio/file/Files.java	Fri Feb 22 18:53:32 2013 +0100
@@ -42,7 +42,6 @@
 import java.io.UncheckedIOException;
 import java.util.*;
 import java.util.function.BiPredicate;
-import java.util.function.Supplier;
 import java.util.stream.CloseableStream;
 import java.util.stream.DelegatingStream;
 import java.util.stream.Stream;
@@ -3222,8 +3221,8 @@
         };
 
         return new DelegatingCloseableStream(ds,
-            Streams.stream(Streams.spliteratorUnknownSize(it,
-                           Spliterator.DISTINCT)));
+            Streams.stream(Spliterators.spliteratorUnknownSize(it,
+                                                               Spliterator.DISTINCT)));
     }
 
     /**
@@ -3314,7 +3313,7 @@
 
         FileTreeIterator itor = FileTreeIterator.iterator(start, maxDepth, options);
         return new DelegatingCloseableStream(itor,
-            Streams.stream(Streams.spliteratorUnknownSize(itor, Spliterator.DISTINCT))
+            Streams.stream(Spliterators.spliteratorUnknownSize(itor, Spliterator.DISTINCT))
                    .map(entry -> entry.getPath()));
     }
 
@@ -3411,7 +3410,7 @@
         }
         FileTreeIterator itor = FileTreeIterator.iterator(start, maxDepth, options);
         return new DelegatingCloseableStream(itor,
-            Streams.stream(Streams.spliteratorUnknownSize(itor, Spliterator.DISTINCT))
+            Streams.stream(Spliterators.spliteratorUnknownSize(itor, Spliterator.DISTINCT))
                    .filter(entry -> matcher.test(entry.getPath(), entry.getFileAttributes()))
                    .map(entry -> entry.getPath()));
     }
--- a/src/share/classes/java/util/Arrays.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/Arrays.java	Fri Feb 22 18:53:32 2013 +0100
@@ -34,7 +34,6 @@
 import java.util.stream.DoubleStream;
 import java.util.stream.IntStream;
 import java.util.stream.LongStream;
-import java.util.stream.Spliterators;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
 
@@ -4487,39 +4486,35 @@
     }
 
     public static <T> Spliterator<T> spliterator(T[] array) {
-        return spliterator(array, 0, array.length);
+        return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
     public static <T> Spliterator<T> spliterator(T[] array, int fromIndex, int toIndex) {
-        checkFromToBounds(array.length, fromIndex, toIndex);
-        return new Spliterators.ArraySpliterator<>(array, fromIndex, toIndex-fromIndex);
+        return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
     public static Spliterator.OfInt spliterator(int[] array) {
-        return spliterator(array, 0, array.length);
+        return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
     public static Spliterator.OfInt spliterator(int[] array, int fromIndex, int toIndex) {
-        checkFromToBounds(array.length, fromIndex, toIndex);
-        return new Spliterators.IntArraySpliterator(array, fromIndex, toIndex-fromIndex);
+        return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
     public static Spliterator.OfLong spliterator(long[] array) {
-        return spliterator(array, 0, array.length);
+        return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
     public static Spliterator.OfLong spliterator(long[] array, int fromIndex, int toIndex) {
-        checkFromToBounds(array.length, fromIndex, toIndex);
-        return new Spliterators.LongArraySpliterator(array, fromIndex, toIndex-fromIndex);
+        return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
     public static Spliterator.OfDouble spliterator(double[] array) {
-        return spliterator(array, 0, array.length);
+        return Spliterators.spliterator(array, Spliterator.ORDERED);
     }
 
     public static Spliterator.OfDouble spliterator(double[] array, int fromIndex, int toIndex) {
-        checkFromToBounds(array.length, fromIndex, toIndex);
-        return new Spliterators.DoubleArraySpliterator(array, fromIndex, toIndex-fromIndex);
+        return Spliterators.spliterator(array, fromIndex, toIndex, Spliterator.ORDERED);
     }
 
     public static <T> Stream<T> stream(T[] array) {
--- a/src/share/classes/java/util/BitSet.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/BitSet.java	Fri Feb 22 18:53:32 2013 +0100
@@ -1202,7 +1202,7 @@
      * @since 1.8
      */
     public IntStream stream() {
-        class BitSetIterator implements IntStream.IntIterator {
+        class BitSetIterator implements PrimitiveIterator.OfInt {
             int next = nextSetBit(0);
 
             @Override
@@ -1222,9 +1222,9 @@
             }
         }
 
-        return Streams.intStream(() -> Streams.intSpliterator(new BitSetIterator(), cardinality(), Spliterator.ORDERED |
-                                                                                                   Spliterator.DISTINCT |
-                                                                                                   Spliterator.SORTED),
+        return Streams.intStream(() -> Spliterators.spliterator(new BitSetIterator(), cardinality(), Spliterator.ORDERED |
+                                                                                                     Spliterator.DISTINCT |
+                                                                                                     Spliterator.SORTED),
                                  Spliterator.SIZED | Spliterator.SUBSIZED |
                                  Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED);
     }
--- a/src/share/classes/java/util/Collection.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/Collection.java	Fri Feb 22 18:53:32 2013 +0100
@@ -484,7 +484,7 @@
      * @return a {@code Stream} of elements in this collection
      */
     default Stream<E> stream() {
-        return Streams.stream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED), Spliterator.SIZED);
+        return Streams.stream(Spliterators.spliterator(this, 0));
     }
 
     /**
@@ -493,7 +493,7 @@
      * @return a {@code Stream} of elements in this collection
      */
     default Stream<E> parallelStream() {
-        return stream().parallel();
+        return Streams.parallelStream(Spliterators.spliterator(this, 0));
     }
 }
 
--- a/src/share/classes/java/util/Collections.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/Collections.java	Fri Feb 22 18:53:32 2013 +0100
@@ -4179,339 +4179,4 @@
         public boolean retainAll(Collection<?> c)   {return q.retainAll(c);}
         // We use inherited addAll; forwarding addAll would be wrong
     }
-
-    /**
-     * Returns a new Spliterator that covers elements obtained by the
-     * given Collection's {@link Collection#toArray} method.
-     *
-     * @param c the collection
-     * @param characteristics properties of this spliterator's
-     * source or elements ({@code SIZED} and {@code SUBSIZED}
-     * are always reported, so need not be supplied.)
-     * @since 1.8
-     */
-    public static <T> Spliterator<T> arraySnapshotSpliterator
-        (Collection<T> c, int characteristics) {
-        return new ArraySnapshotSpliterator<T>(c, characteristics);
-    }
-
-    /**
-     * Creates a new Spliterator covering all of the given array.
-     *
-     * @param array the array, assumed to be unmodified during use
-     * @param characteristics properties of this spliterator's
-     * source or elements ({@code SIZED} and {@code SUBSIZED}
-     * are always reported, so need not be supplied.)
-     * @since 1.8
-     */
-    public static <T> Spliterator<T> arraySnapshotSpliterator
-        (Object[] array, int characteristics) {
-        return  new ArraySnapshotSpliterator<T>(array, characteristics);
-    }
-
-    /**
-     * Creates a new Spliterator covering the given range of the given
-     * array.
-     *
-     * @param array the array, assumed to be unmodified during use
-     * @param characteristics properties of this spliterator's
-     * source or elements ({@code SIZED} and {@code SUBSIZED}
-     * are always reported, so need not be supplied.)
-     *
-     * @param array the array, assumed to be unmodified during use
-     * @param origin the least index (inclusive) to cover
-     * @param fence one past the greatest index to cover
-     * @param characteristics properties of this spliterator's
-     * source or elements ({@code SIZED} and {@code SUBSIZED}
-     * are always reported, so need not be supplied.)
-     * @since 1.8
-     */
-    public static <T> Spliterator<T> arraySnapshotSpliterator
-        (Object[] array, int origin, int fence, int characteristics) {
-        return  new ArraySnapshotSpliterator<T>(array, origin, fence,
-                                                characteristics);
-    }
-
-    /**
-     * Returns a new basic Spliterator using a given Iterator for
-     * element operations, and with a given initially reported
-     * size. The spliterator implements {@code trySplit} to permit
-     * limited parallelism.
-     *
-     * @param iterator the iterator for the source
-     * @param size the number of elements in the source, to be reported
-     * as initial {@code estimateSize}.
-     * @param characteristics properties of this spliterator's
-     * source or elements.
-     * @since 1.8
-     */
-    public static <T> Spliterator<T> iteratorBasedSpliterator
-        (Iterator<T> iterator, long size, int characteristics) {
-        return new IteratorSpliterator<T>(iterator, size, characteristics);
-    }
-
-    /**
-     * Returns a basic Spliterator using a given Iterator for element
-     * operations, with no initial size estimate. The spliterator
-     * implements {@code trySplit} to permit limited parallelism.
-     *
-     * @param iterator the iterator for the source
-     * @param characteristics properties of this spliterator's
-     * source or elements.
-     * @since 1.8
-     */
-    public static <T> Spliterator<T> iteratorBasedSpliterator
-        (Iterator<T> iterator, int characteristics) {
-        return new IteratorSpliterator<T>(iterator, characteristics);
-    }
-
-    /**
-     * Returns a new basic Spliterator using the given collection's
-     * {@link Collection#iterator()) for traversal, and reporting its
-     * {@link Collection#size()) as its initial size.  The spliterator
-     * implements {@code trySplit} to permit limited parallelism.
-     *
-     * @param c the collection
-     * @param characteristics properties of this spliterator's
-     * source or elements.
-     * @since 1.8
-     */
-    public static <T> Spliterator<T> iteratorBasedSpliterator
-        (Collection<T> c, int characteristics) {
-        return new IteratorSpliterator<T>(c, characteristics);
-    }
-
-    /**
-     * A Spliterator designed for use by those Collections and related
-     * sources that traverse and split elements maintained in an
-     * unmodifiable {@code Object[]} array. The spliterator covers a
-     * given array snapshotting elements; either the one returned by a
-     * Collection's toArray method, or an explicit array and range
-     * passed in a constructor.
-     */
-    static final class ArraySnapshotSpliterator<T> implements Spliterator<T> {
-        /**
-         * The array, explicitly typed as Object[]. Unlike in some other
-         * classes (see for example CR 6260652), we do not need to
-         * screen arguments to ensure they are exactly of type Object[]
-         * so long as no methods write into the array or serialize it,
-         * which we ensure here by defining this class as final.
-         */
-        private final Object[] array;
-        private int index;        // current index, modified on advance/split
-        private final int fence;  // one past last index
-        private final int characteristics;
-
-        /**
-         * Creates a new spliterator operating on the array returned
-         * by the given collection's toArray method, and with the
-         * given characteristics.
-         *
-         * @param c the collection
-         * @param characteristics properties of this spliterator's
-         * source or elements ({@code SIZED} and {@code SUBSIZED}
-         * are always reported, so need not be supplied.)
-         */
-        public ArraySnapshotSpliterator(Collection<T> c, int characteristics) {
-            this.array = c.toArray();
-            this.fence = array.length;
-            this.characteristics = characteristics;
-            this.index = 0;
-        }
-
-        /**
-         * Creates a new spliterator covering all of the given array.
-         * @param array the array, assumed to be unmodified during use
-         * @param characteristics properties of this spliterator's
-         * source or elements ({@code SIZED} and {@code SUBSIZED}
-         * are always reported, so need not be supplied.)
-         */
-        public ArraySnapshotSpliterator(Object[] array, int characteristics) {
-            this(array, 0, array.length, characteristics);
-        }
-
-        /**
-         * Creates a new spliterator covering the given array and range
-         * @param array the array, assumed to be unmodified during use
-         * @param origin the least index (inclusive) to cover
-         * @param fence one past the greatest index to cover
-         * @param characteristics properties of this spliterator's
-         * source or elements ({@code SIZED} and {@code SUBSIZED}
-         * are always reported, so need not be supplied.)
-         */
-        public ArraySnapshotSpliterator(Object[] array, int origin, int fence,
-                                        int characteristics) {
-            this.array = array;
-            this.index = origin;
-            this.fence = fence;
-            this.characteristics = characteristics;
-        }
-
-        public Spliterator<T> trySplit() {
-            int lo = index, mid = (lo + fence) >>> 1;
-            return (lo >= mid) ? null :
-                new ArraySnapshotSpliterator<T>(array, lo, index = mid,
-                                                characteristics);
-        }
-
-        @SuppressWarnings("unchecked")
-        public void forEach(Consumer<? super T> action) {
-            Object[] a; int i, hi; // hoist accesses and checks from loop
-            if (action == null)
-                throw new NullPointerException();
-            if ((a = array).length >= (hi = fence) &&
-                (i = index) >= 0 && i < (index = hi)) {
-                do { action.accept((T)a[i]); } while (++i < hi);
-            }
-        }
-
-        public boolean tryAdvance(Consumer<? super T> action) {
-            if (action == null)
-                throw new NullPointerException();
-            if (index >= 0 && index < fence) {
-                @SuppressWarnings("unchecked") T e = (T) array[index++];
-                action.accept(e);
-                return true;
-            }
-            return false;
-        }
-
-        public long estimateSize() { return (long)(fence - index); }
-
-        public int characteristics() {
-            return characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
-        }
-    }
-
-    /**
-     * A basic Spliterator using a given Iterator for element
-     * operations. The spliterator implements {@code trySplit} to
-     * permit limited parallelism.
-     */
-    static final class IteratorSpliterator<T> implements Spliterator<T> {
-        static final int MAX_BATCH = 1 << 12;  // saturate batch size; see below
-        private final Collection<T> collection; // null OK
-        private Iterator<T> it;
-        private final int characteristics;
-        private long est;             // size estimate
-        private int batch;            // batch size for splits
-
-        /**
-         * Creates a new spliterator using the given given
-         * collection's {@link Collection#iterator()) for traversal, and
-         * reporting its {@link Collection#size()) as its initial size.
-         *
-         * @param c the collection
-         * @param characteristics properties of this spliterator's
-         * source or elements.
-         */
-        public IteratorSpliterator(Collection<T> collection, int characteristics) {
-            this.collection = collection;
-            this.it = null;
-            this.characteristics = characteristics | Spliterator.SIZED |
-                Spliterator.SIZED;
-        }
-
-        /**
-         * Creates a new spliterator using the given iterator
-         * for traversal, and reporting the given initial size
-         * and characteristics.
-         *
-         * @param iterator the iterator for the source
-         * @param size the number of elements in the source
-         * @param characteristics properties of this spliterator's
-         * source or elements.
-         */
-        public IteratorSpliterator(Iterator<T> iterator, long size,
-                                   int characteristics) {
-            this.collection = null;
-            this.it = iterator;
-            this.est = size;
-            this.characteristics = characteristics | Spliterator.SIZED |
-                Spliterator.SIZED;
-        }
-
-        /**
-         * Creates a new spliterator using the given iterator for a
-         * source of unknown size, reporting the given
-         * characteristics.
-         *
-         * @param iterator the iterator for the source
-         * @param characteristics properties of this spliterator's
-         * source or elements.
-         */
-        public IteratorSpliterator(Iterator<T> iterator, int characteristics) {
-            this.collection = null;
-            this.it = iterator;
-            this.est = Long.MAX_VALUE;
-            this.characteristics = characteristics;
-        }
-
-        public Spliterator<T> trySplit() {
-            /*
-             * Split into arrays of arithmetically increasing batch
-             * sizes, giving up at MAX_BATCH.  This will only improve
-             * parallel performance if per-element Consumer actions
-             * are more costly than transfering them into an array.
-             * The use of an arithmetic progression in split sizes
-             * provides overhead vs parallelism bounds that do not
-             * particularly favor or penalize cases of lightweight vs
-             * heavyweight element operations, across combinations of
-             * #elements vs #cores, whether or not either are known.
-             * We generate O(sqrt(#elements)) splits, allowing
-             * O(sqrt(#cores)) potential speedup. The cutoff value
-             * limits asymptotic speedups for large #elements, but is
-             * needed to limit runaway overhead impact when the cost
-             * of allocating, filling, and splitting off arrays dwarfs
-             * all other processing.
-             */
-            int n;
-            if (it == null) {
-                est = (long)collection.size();
-                it = collection.iterator();
-            }
-            if (it.hasNext() && (n = batch + 1) > 0 && n <= MAX_BATCH) {
-                Object[] a = new Object[batch = n];
-                int i = 0;
-                do { a[i++] = it.next(); } while (it.hasNext() && i < n);
-                if (est != Long.MAX_VALUE)
-                    est -= i;
-                return new ArraySnapshotSpliterator<T>(a, 0, i, characteristics);
-            }
-            return null;
-        }
-
-        public void forEach(Consumer<? super T> action) {
-            if (action == null) throw new NullPointerException();
-            if (it == null) {
-                est = (long)collection.size();
-                it = collection.iterator();
-            }
-            while (it.hasNext())
-                action.accept(it.next());
-        }
-
-        public boolean tryAdvance(Consumer<? super T> action) {
-            if (action == null) throw new NullPointerException();
-            if (it == null) {
-                est = (long)collection.size();
-                it = collection.iterator();
-            }
-            if (it.hasNext()) {
-                action.accept(it.next());
-                return true;
-            }
-            return false;
-        }
-
-        public long estimateSize() {
-            if (it == null) {
-                it = collection.iterator();
-                return est = (long)collection.size();
-            }
-            return est;
-        }
-
-        public int characteristics() { return characteristics; }
-    }
 }
--- a/src/share/classes/java/util/HashMap.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/HashMap.java	Fri Feb 22 18:53:32 2013 +0100
@@ -929,8 +929,8 @@
             if (HashMap.this.getClass() == HashMap.class)
                 return new KeySpliterator<K,V>(HashMap.this, 0, -1, 0, 0);
             else
-                return Collections.iteratorBasedSpliterator
-                    (this, Spliterator.SIZED | Spliterator.DISTINCT);
+                return Spliterators.spliterator
+                        (this, Spliterator.SIZED | Spliterator.DISTINCT);
         }
 
         public Stream<K> stream() {
@@ -978,8 +978,8 @@
             if (HashMap.this.getClass() == HashMap.class)
                 return new ValueSpliterator<K,V>(HashMap.this, 0, -1, 0, 0);
             else
-                return Collections.iteratorBasedSpliterator
-                    (this, Spliterator.SIZED);
+                return Spliterators.spliterator
+                        (this, Spliterator.SIZED);
         }
 
         public Stream<V> stream() {
@@ -1041,8 +1041,8 @@
             if (HashMap.this.getClass() == HashMap.class)
                 return new EntrySpliterator<K,V>(HashMap.this, 0, -1, 0, 0);
             else
-                return Collections.iteratorBasedSpliterator
-                    (this, Spliterator.SIZED | Spliterator.DISTINCT);
+                return Spliterators.spliterator
+                        (this, Spliterator.SIZED | Spliterator.DISTINCT);
         }
 
         public Stream<Map.Entry<K,V>> stream() {
--- a/src/share/classes/java/util/LinkedHashSet.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/LinkedHashSet.java	Fri Feb 22 18:53:32 2013 +0100
@@ -174,13 +174,11 @@
 
     @Override
     public Stream<E> stream() {
-        return Streams.stream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED),
-                              Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED);
+        return Streams.stream(Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED));
     }
 
     @Override
     public Stream<E> parallelStream() {
-        return Streams.parallelStream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED),
-                                      Spliterator.SIZED | Spliterator.DISTINCT | Spliterator.ORDERED);
+        return Streams.parallelStream(Spliterators.spliterator(this, Spliterator.DISTINCT | Spliterator.ORDERED));
     }
 }
--- a/src/share/classes/java/util/LinkedList.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/LinkedList.java	Fri Feb 22 18:53:32 2013 +0100
@@ -1196,8 +1196,8 @@
                     est = 0;
                 else if ((est -= i) <= 0)
                     est = 1; // may eventually cause CME
-                return Collections.arraySnapshotSpliterator
-                    (a, 0, i, Spliterator.ORDERED);
+                return Spliterators.spliterator
+                        (a, 0, i, Spliterator.ORDERED);
             }
             return null;
         }
--- a/src/share/classes/java/util/List.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/List.java	Fri Feb 22 18:53:32 2013 +0100
@@ -634,8 +634,7 @@
      */
     @Override
     public default Stream<E> stream() {
-        return Streams.stream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.ORDERED),
-                              Spliterator.SIZED | Spliterator.ORDERED);
+        return Streams.stream(Spliterators.spliterator(this, Spliterator.ORDERED));
     }
 
     /**
@@ -647,8 +646,7 @@
      */
     @Override
     public default Stream<E> parallelStream() {
-        return Streams.parallelStream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.ORDERED),
-                                      Spliterator.SIZED | Spliterator.ORDERED);
+        return Streams.parallelStream(Spliterators.spliterator(this, Spliterator.ORDERED));
     }
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/util/PrimitiveIterator.java	Fri Feb 22 18:53:32 2013 +0100
@@ -0,0 +1,122 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package java.util;
+
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+public interface PrimitiveIterator<T> extends Iterator<T> {
+
+    public static interface OfInt extends PrimitiveIterator<Integer> {
+
+        @Override
+        default Integer next() {
+            Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int in next", getClass().getName());
+            return nextInt();
+        }
+
+        int nextInt();
+
+        @Override
+        default void forEach(Consumer<? super Integer> sink) {
+            if (sink instanceof IntConsumer) {
+                forEachInt((IntConsumer) sink);
+            }
+            else {
+                Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int in forEach", getClass().getName());
+                while (hasNext()) {
+                    sink.accept(nextInt());
+                }
+            }
+        }
+
+        default void forEachInt(IntConsumer block) {
+            while (hasNext())
+                block.accept(nextInt());
+        }
+    }
+
+    public static interface OfLong extends PrimitiveIterator<Long> {
+
+        @Override
+        default Long next() {
+            Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int in next", getClass().getName());
+            return nextLong();
+        }
+
+        long nextLong();
+
+        @Override
+        default void forEach(Consumer<? super Long> sink) {
+            if (sink instanceof LongConsumer) {
+                forEachLong((LongConsumer) sink);
+            }
+            else {
+                Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int in forEach", getClass().getName());
+                while (hasNext()) {
+                    sink.accept(nextLong());
+                }
+            }
+        }
+
+        default void forEachLong(LongConsumer block) {
+            while (hasNext())
+                block.accept(nextLong());
+        }
+    }
+
+    public static interface OfDouble extends PrimitiveIterator<Double> {
+
+        @Override
+        default Double next() {
+            Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int in next", getClass().getName());
+            return nextDouble();
+        }
+
+        double nextDouble();
+
+        @Override
+        default void forEach(Consumer<? super Double> sink) {
+            if (sink instanceof DoubleConsumer) {
+                forEachDouble((DoubleConsumer) sink);
+            }
+            else {
+                Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} using boxed int in forEach", getClass().getName());
+                while (hasNext()) {
+                    sink.accept(nextDouble());
+                }
+            }
+        }
+
+        default void forEachDouble(DoubleConsumer block) {
+            while (hasNext())
+                block.accept(nextDouble());
+        }
+    }
+}
--- a/src/share/classes/java/util/Set.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/Set.java	Fri Feb 22 18:53:32 2013 +0100
@@ -388,13 +388,11 @@
 
     @Override
     default Stream<E> stream() {
-        return Streams.stream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.DISTINCT),
-                              Spliterator.SIZED | Spliterator.DISTINCT);
+        return Streams.stream(Spliterators.spliterator(this, Spliterator.DISTINCT));
     }
 
     @Override
     default Stream<E> parallelStream() {
-        return Streams.parallelStream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.DISTINCT),
-                                      Spliterator.SIZED | Spliterator.DISTINCT);
+        return Streams.parallelStream(Spliterators.spliterator(this, Spliterator.DISTINCT));
     }
 }
--- a/src/share/classes/java/util/SortedSet.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/SortedSet.java	Fri Feb 22 18:53:32 2013 +0100
@@ -225,17 +225,13 @@
 
     @Override
     default Stream<E> stream() {
-        return Streams.stream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.DISTINCT |
-                                                                            Spliterator.SORTED | Spliterator.ORDERED),
-                              Spliterator.SIZED | Spliterator.DISTINCT |
-                              Spliterator.SORTED | Spliterator.ORDERED);
+        return Streams.stream(Spliterators.spliterator(
+                this, Spliterator.DISTINCT | Spliterator.SORTED | Spliterator.ORDERED));
     }
 
     @Override
     default Stream<E> parallelStream() {
-        return Streams.parallelStream(() -> Streams.spliterator(iterator(), size(), Spliterator.SIZED | Spliterator.DISTINCT |
-                                                                                    Spliterator.SORTED | Spliterator.ORDERED),
-                                      Spliterator.SIZED | Spliterator.DISTINCT |
-                                      Spliterator.SORTED | Spliterator.ORDERED);
+        return Streams.parallelStream(Spliterators.spliterator(
+                this, Spliterator.DISTINCT | Spliterator.SORTED | Spliterator.ORDERED));
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/util/Spliterators.java	Fri Feb 22 18:53:32 2013 +0100
@@ -0,0 +1,1187 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package java.util;
+
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+
+/**
+ * This class contains various methods that operate on or return instances of {@link Spliterator}.
+ */
+public class Spliterators {
+
+    // Suppresses default constructor, ensuring non-instantiability.
+    private Spliterators() {}
+
+    // Empty spliterators
+
+    public static <T> Spliterator<T> emptySpliterator() {
+        return new EmptySpliterator<>();
+    }
+
+    public static Spliterator.OfInt emptyIntSpliterator() {
+        return new EmptySpliterator.OfInt();
+    }
+
+    public static Spliterator.OfLong emptyLongSpliterator() {
+        return new EmptySpliterator.OfLong();
+    }
+
+    public static Spliterator.OfDouble emptyDoubleSpliterator() {
+        return new EmptySpliterator.OfDouble();
+    }
+
+    // Array-based spliterators
+
+    /**
+     * Creates a new Spliterator covering all of the given array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static <T> Spliterator<T> spliterator(Object[] array, int characteristics) {
+        return new ArraySpliterator<>(array, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator covering the given range of the given
+     * array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param origin the least index (inclusive) to cover
+     * @param fence one past the greatest index to cover
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static <T> Spliterator<T> spliterator(Object[] array, int origin, int fence, int characteristics) {
+        checkFromToBounds(array.length, origin, fence);
+        return new ArraySpliterator<>(array, origin, fence, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator.OfInt covering all of the given array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static Spliterator.OfInt spliterator(int[] array, int characteristics) {
+        return new IntArraySpliterator(array, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator.OfInt covering the given range of the given
+     * array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param origin the least index (inclusive) to cover
+     * @param fence one past the greatest index to cover
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static Spliterator.OfInt spliterator(int[] array, int origin, int fence, int characteristics) {
+        checkFromToBounds(array.length, origin, fence);
+        return new IntArraySpliterator(array, origin, fence, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator.OfLong covering all of the given array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static Spliterator.OfLong spliterator(long[] array, int characteristics) {
+        return new LongArraySpliterator(array, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator.OfLong covering the given range of the given
+     * array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param origin the least index (inclusive) to cover
+     * @param fence one past the greatest index to cover
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static Spliterator.OfLong spliterator(long[] array, int origin, int fence, int characteristics) {
+        checkFromToBounds(array.length, origin, fence);
+        return new LongArraySpliterator(array, origin, fence, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator.OfDouble covering all of the given array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static Spliterator.OfDouble spliterator(double[] array, int characteristics) {
+        return new DoubleArraySpliterator(array, characteristics);
+    }
+
+    /**
+     * Creates a new Spliterator.OfDouble covering the given range of the given
+     * array.
+     *
+     * @param array the array, assumed to be unmodified during use
+     * @param origin the least index (inclusive) to cover
+     * @param fence one past the greatest index to cover
+     * @param characteristics properties of this spliterator's
+     * source or elements ({@code SIZED} and {@code SUBSIZED}
+     * are always reported, so need not be supplied.)
+     * @since 1.8
+     */
+    public static Spliterator.OfDouble spliterator(double[] array, int origin, int fence, int characteristics) {
+        checkFromToBounds(array.length, origin, fence);
+        return new DoubleArraySpliterator(array, origin, fence, characteristics);
+    }
+
+    private static void checkFromToBounds(int arrayLength, int origin, int fence) {
+        if (origin > fence) {
+            throw new IllegalArgumentException(
+                    "origin(" + origin + ") > fence(" + fence + ")");
+        }
+        if (origin < 0) {
+            throw new ArrayIndexOutOfBoundsException(origin);
+        }
+        if (fence > arrayLength) {
+            throw new ArrayIndexOutOfBoundsException(fence);
+        }
+    }
+
+    // Iterator-based spliterators
+
+    /**
+     * Returns a new basic Spliterator using the given collection's
+     * {@link java.util.Collection#iterator()) for traversal, and reporting its
+     * {@link java.util.Collection#size()) as its initial size.  The spliterator
+     * implements {@code trySplit} to permit limited parallelism.
+     *
+     * @param c the collection
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static <T> Spliterator<T> spliterator(Collection<T> c, int characteristics) {
+        return new IteratorSpliterator<>(c, characteristics);
+    }
+
+    /**
+     * Returns a new basic Spliterator using a given Iterator for
+     * element operations, and with a given initially reported
+     * size. The spliterator implements {@code trySplit} to permit
+     * limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param size the number of elements in the source, to be reported
+     * as initial {@code estimateSize}.
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static <T> Spliterator<T> spliterator(Iterator<T> iterator, long size, int characteristics) {
+        return new IteratorSpliterator<>(iterator, size, characteristics);
+    }
+
+    /**
+     * Returns a basic Spliterator using a given Iterator for element
+     * operations, with no initial size estimate. The spliterator
+     * implements {@code trySplit} to permit limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static <T> Spliterator<T> spliteratorUnknownSize(Iterator<T> iterator, int characteristics) {
+        return new IteratorSpliterator<>(iterator, characteristics);
+    }
+
+    /**
+     * Returns a new basic Spliterator.OfInt using a given IntStream.IntIterator for
+     * element operations, and with a given initially reported
+     * size. The spliterator implements {@code trySplit} to permit
+     * limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param size the number of elements in the source, to be reported
+     * as initial {@code estimateSize}.
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static Spliterator.OfInt spliterator(PrimitiveIterator.OfInt iterator, long size, int characteristics) {
+        return new IntIteratorSpliterator(iterator, size, characteristics);
+    }
+
+    /**
+     * Returns a basic Spliterator.OfInt using a given IntStream.IntIterator for element
+     * operations, with no initial size estimate. The spliterator
+     * implements {@code trySplit} to permit limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static Spliterator.OfInt spliteratorUnknownSize(PrimitiveIterator.OfInt iterator, int characteristics) {
+        return new IntIteratorSpliterator(iterator, characteristics);
+    }
+
+    /**
+     * Returns a new basic Spliterator.OfLong using a given LongStream.LongIterator for
+     * element operations, and with a given initially reported
+     * size. The spliterator implements {@code trySplit} to permit
+     * limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param size the number of elements in the source, to be reported
+     * as initial {@code estimateSize}.
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static Spliterator.OfLong spliterator(PrimitiveIterator.OfLong iterator, long size, int characteristics) {
+        return new LongIteratorSpliterator(iterator, size, characteristics);
+    }
+
+    /**
+     * Returns a basic Spliterator.OfLong using a given LongStream.LongIterator for element
+     * operations, with no initial size estimate. The spliterator
+     * implements {@code trySplit} to permit limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static Spliterator.OfLong spliteratorUnknownSize(PrimitiveIterator.OfLong iterator, int characteristics) {
+        return new LongIteratorSpliterator(iterator, characteristics);
+    }
+
+    /**
+     * Returns a new basic Spliterator.OfDouble using a given DoubleStream.DoubleIterator for
+     * element operations, and with a given initially reported
+     * size. The spliterator implements {@code trySplit} to permit
+     * limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param size the number of elements in the source, to be reported
+     * as initial {@code estimateSize}.
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static Spliterator.OfDouble spliterator(PrimitiveIterator.OfDouble iterator, long size, int characteristics) {
+        return new DoubleIteratorSpliterator(iterator, size, characteristics);
+    }
+
+    /**
+     * Returns a basic Spliterator.OfDouble using a given DoubleStream.DoubleIterator for element
+     * operations, with no initial size estimate. The spliterator
+     * implements {@code trySplit} to permit limited parallelism.
+     *
+     * @param iterator the iterator for the source
+     * @param characteristics properties of this spliterator's
+     * source or elements.
+     * @since 1.8
+     */
+    public static Spliterator.OfDouble spliteratorUnknownSize(PrimitiveIterator.OfDouble iterator, int characteristics) {
+        return new DoubleIteratorSpliterator(iterator, characteristics);
+    }
+
+    // Iterators from Spliterators
+    
+    public static<T> Iterator<T> iteratorFromSpliterator(Spliterator<? extends T> spliterator) {
+        class Adapter implements Iterator<T>, Consumer<T> {
+            boolean valueReady = false;
+            T nextElement;
+
+            @Override
+            public void accept(T t) {
+                valueReady = true;
+                nextElement = t;
+            }
+
+            @Override
+            public boolean hasNext() {
+                Consumer<T> b = this;
+                if (!valueReady)
+                    spliterator.tryAdvance(b);
+                return valueReady;
+            }
+
+            @Override
+            public T next() {
+                if (!valueReady && !hasNext())
+                    throw new NoSuchElementException();
+                else {
+                    valueReady = false;
+                    return nextElement;
+                }
+            }
+        }
+
+        return new Adapter();
+    }
+
+    public static PrimitiveIterator.OfInt iteratorFromSpliterator(Spliterator.OfInt spliterator) {
+        class Adapter implements PrimitiveIterator.OfInt, IntConsumer {
+            boolean valueReady = false;
+            int nextElement;
+
+            @Override
+            public void accept(int t) {
+                valueReady = true;
+                nextElement = t;
+            }
+
+            @Override
+            public boolean hasNext() {
+                if (!valueReady)
+                    spliterator.tryAdvance(this);
+                return valueReady;
+            }
+
+            @Override
+            public int nextInt() {
+                if (!valueReady && !hasNext())
+                    throw new NoSuchElementException();
+                else {
+                    valueReady = false;
+                    return nextElement;
+                }
+            }
+        }
+
+        return new Adapter();
+    }
+
+    public static PrimitiveIterator.OfLong iteratorFromSpliterator(Spliterator.OfLong spliterator) {
+        class Adapter implements PrimitiveIterator.OfLong, LongConsumer {
+            boolean valueReady = false;
+            long nextElement;
+
+            @Override
+            public void accept(long t) {
+                valueReady = true;
+                nextElement = t;
+            }
+
+            @Override
+            public boolean hasNext() {
+                if (!valueReady)
+                    spliterator.tryAdvance(this);
+                return valueReady;
+            }
+
+            @Override
+            public long nextLong() {
+                if (!valueReady && !hasNext())
+                    throw new NoSuchElementException();
+                else {
+                    valueReady = false;
+                    return nextElement;
+                }
+            }
+        }
+
+        return new Adapter();
+    }
+
+    public static PrimitiveIterator.OfDouble iteratorFromSpliterator(Spliterator.OfDouble spliterator) {
+        class Adapter implements PrimitiveIterator.OfDouble, DoubleConsumer {
+            boolean valueReady = false;
+            double nextElement;
+
+            @Override
+            public void accept(double t) {
+                valueReady = true;
+                nextElement = t;
+            }
+
+            @Override
+            public boolean hasNext() {
+                if (!valueReady)
+                    spliterator.tryAdvance(this);
+                return valueReady;
+            }
+
+            @Override
+            public double nextDouble() {
+                if (!valueReady && !hasNext())
+                    throw new NoSuchElementException();
+                else {
+                    valueReady = false;
+                    return nextElement;
+                }
+            }
+        }
+
+        return new Adapter();
+    }
+
+    // Implementations
+
+    private static class EmptySpliterator<T> implements Spliterator<T> {
+
+        @Override
+        public Spliterator<T> trySplit() {
+            return null;
+        }
+
+        @Override
+        public boolean tryAdvance(Consumer<? super T> consumer) {
+            return false;
+        }
+
+        @Override
+        public void forEach(Consumer<? super T> consumer) { }
+
+        @Override
+        public long estimateSize() {
+            return 0;
+        }
+
+        @Override
+        public int characteristics() {
+            return Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+
+        private static class OfInt extends EmptySpliterator<Integer> implements Spliterator.OfInt {
+            @Override
+            public Spliterator.OfInt trySplit() {
+                return null;
+            }
+
+            @Override
+            public boolean tryAdvance(IntConsumer consumer) {
+                return false;
+            }
+
+            @Override
+            public void forEach(IntConsumer consumer) {
+            }
+        }
+
+        private static class OfLong extends EmptySpliterator<Long> implements Spliterator.OfLong {
+            @Override
+            public Spliterator.OfLong trySplit() {
+                return null;
+            }
+
+            @Override
+            public boolean tryAdvance(LongConsumer consumer) {
+                return false;
+            }
+
+            @Override
+            public void forEach(LongConsumer consumer) {
+            }
+        }
+
+        private static class OfDouble extends EmptySpliterator<Double> implements Spliterator.OfDouble {
+            @Override
+            public Spliterator.OfDouble trySplit() {
+                return null;
+            }
+
+            @Override
+            public boolean tryAdvance(DoubleConsumer consumer) {
+                return false;
+            }
+
+            @Override
+            public void forEach(DoubleConsumer consumer) {
+            }
+        }
+    }
+
+    // Array-based spliterators
+
+    /**
+     * A Spliterator designed for use by sources that traverse and split
+     * elements maintained in an unmodifiable {@code Object[]} array.
+     */
+    static final class ArraySpliterator<T> implements Spliterator<T> {
+        /**
+         * The array, explicitly typed as Object[]. Unlike in some other
+         * classes (see for example CR 6260652), we do not need to
+         * screen arguments to ensure they are exactly of type Object[]
+         * so long as no methods write into the array or serialize it,
+         * which we ensure here by defining this class as final.
+         */
+        private final Object[] array;
+        private int index;        // current index, modified on advance/split
+        private final int fence;  // one past last index
+        private final int characteristics;
+
+        /**
+         * Creates a new spliterator covering all of the given array.
+         * @param array the array, assumed to be unmodified during use
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public ArraySpliterator(Object[] array, int characteristics) {
+            this(array, 0, array.length, characteristics);
+        }
+
+        /**
+         * Creates a new spliterator covering the given array and range
+         * @param array the array, assumed to be unmodified during use
+         * @param origin the least index (inclusive) to cover
+         * @param fence one past the greatest index to cover
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public ArraySpliterator(Object[] array, int origin, int fence, int characteristics) {
+            this.array = array;
+            this.index = origin;
+            this.fence = fence;
+            this.characteristics = characteristics;
+        }
+
+        public Spliterator<T> trySplit() {
+            int lo = index, mid = (lo + fence) >>> 1;
+            return (lo >= mid)
+                   ? null
+                   : new ArraySpliterator<>(array, lo, index = mid, characteristics);
+        }
+
+        @SuppressWarnings("unchecked")
+        public void forEach(Consumer<? super T> action) {
+            Object[] a; int i, hi; // hoist accesses and checks from loop
+            if (action == null)
+                throw new NullPointerException();
+            if ((a = array).length >= (hi = fence) &&
+                (i = index) >= 0 && i < (index = hi)) {
+                do { action.accept((T)a[i]); } while (++i < hi);
+            }
+        }
+
+        public boolean tryAdvance(Consumer<? super T> action) {
+            if (action == null)
+                throw new NullPointerException();
+            if (index >= 0 && index < fence) {
+                @SuppressWarnings("unchecked") T e = (T) array[index++];
+                action.accept(e);
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() { return (long)(fence - index); }
+
+        public int characteristics() {
+            return characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+    }
+
+    /**
+     * A Spliterator.OfInt designed for use by sources that traverse and split
+     * elements maintained in an unmodifiable {@code int[]} array.
+     */
+    static final class IntArraySpliterator implements Spliterator.OfInt {
+        private final int[] array;
+        private int index;        // current index, modified on advance/split
+        private final int fence;  // one past last index
+        private final int characteristics;
+
+        /**
+         * Creates a new spliterator covering all of the given array.
+         * @param array the array, assumed to be unmodified during use
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public IntArraySpliterator(int[] array, int characteristics) {
+            this(array, 0, array.length, characteristics);
+        }
+
+        /**
+         * Creates a new spliterator covering the given array and range
+         * @param array the array, assumed to be unmodified during use
+         * @param origin the least index (inclusive) to cover
+         * @param fence one past the greatest index to cover
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public IntArraySpliterator(int[] array, int origin, int fence, int characteristics) {
+            this.array = array;
+            this.index = origin;
+            this.fence = fence;
+            this.characteristics = characteristics;
+        }
+
+        public OfInt trySplit() {
+            int lo = index, mid = (lo + fence) >>> 1;
+            return (lo >= mid)
+                   ? null
+                   : new IntArraySpliterator(array, lo, index = mid, characteristics);
+        }
+
+        public void forEach(IntConsumer action) {
+            int[] a; int i, hi; // hoist accesses and checks from loop
+            if (action == null)
+                throw new NullPointerException();
+            if ((a = array).length >= (hi = fence) &&
+                (i = index) >= 0 && i < (index = hi)) {
+                do { action.accept(a[i]); } while (++i < hi);
+            }
+        }
+
+        public boolean tryAdvance(IntConsumer action) {
+            if (action == null)
+                throw new NullPointerException();
+            if (index >= 0 && index < fence) {
+                action.accept(array[index++]);
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() { return (long)(fence - index); }
+
+        public int characteristics() {
+            return characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+    }
+
+    /**
+     * A Spliterator.OfLong designed for use by sources that traverse and split
+     * elements maintained in an unmodifiable {@code int[]} array.
+     */
+    static final class LongArraySpliterator implements Spliterator.OfLong {
+        private final long[] array;
+        private int index;        // current index, modified on advance/split
+        private final int fence;  // one past last index
+        private final int characteristics;
+
+        /**
+         * Creates a new spliterator covering all of the given array.
+         * @param array the array, assumed to be unmodified during use
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public LongArraySpliterator(long[] array, int characteristics) {
+            this(array, 0, array.length, characteristics);
+        }
+
+        /**
+         * Creates a new spliterator covering the given array and range
+         * @param array the array, assumed to be unmodified during use
+         * @param origin the least index (inclusive) to cover
+         * @param fence one past the greatest index to cover
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public LongArraySpliterator(long[] array, int origin, int fence, int characteristics) {
+            this.array = array;
+            this.index = origin;
+            this.fence = fence;
+            this.characteristics = characteristics;
+        }
+
+        public OfLong trySplit() {
+            int lo = index, mid = (lo + fence) >>> 1;
+            return (lo >= mid)
+                   ? null
+                   : new LongArraySpliterator(array, lo, index = mid, characteristics);
+        }
+
+        public void forEach(LongConsumer action) {
+            long[] a; int i, hi; // hoist accesses and checks from loop
+            if (action == null)
+                throw new NullPointerException();
+            if ((a = array).length >= (hi = fence) &&
+                (i = index) >= 0 && i < (index = hi)) {
+                do { action.accept(a[i]); } while (++i < hi);
+            }
+        }
+
+        public boolean tryAdvance(LongConsumer action) {
+            if (action == null)
+                throw new NullPointerException();
+            if (index >= 0 && index < fence) {
+                action.accept(array[index++]);
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() { return (long)(fence - index); }
+
+        public int characteristics() {
+            return characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+    }
+
+    /**
+     * A Spliterator.OfDouble designed for use by sources that traverse and split
+     * elements maintained in an unmodifiable {@code int[]} array.
+     */
+    static final class DoubleArraySpliterator implements Spliterator.OfDouble {
+        private final double[] array;
+        private int index;        // current index, modified on advance/split
+        private final int fence;  // one past last index
+        private final int characteristics;
+
+        /**
+         * Creates a new spliterator covering all of the given array.
+         * @param array the array, assumed to be unmodified during use
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public DoubleArraySpliterator(double[] array, int characteristics) {
+            this(array, 0, array.length, characteristics);
+        }
+
+        /**
+         * Creates a new spliterator covering the given array and range
+         * @param array the array, assumed to be unmodified during use
+         * @param origin the least index (inclusive) to cover
+         * @param fence one past the greatest index to cover
+         * @param characteristics properties of this spliterator's
+         * source or elements ({@code SIZED} and {@code SUBSIZED}
+         * are always reported, so need not be supplied.)
+         */
+        public DoubleArraySpliterator(double[] array, int origin, int fence, int characteristics) {
+            this.array = array;
+            this.index = origin;
+            this.fence = fence;
+            this.characteristics = characteristics;
+        }
+
+        public OfDouble trySplit() {
+            int lo = index, mid = (lo + fence) >>> 1;
+            return (lo >= mid)
+                   ? null
+                   : new DoubleArraySpliterator(array, lo, index = mid, characteristics);
+        }
+
+        public void forEach(DoubleConsumer action) {
+            double[] a; int i, hi; // hoist accesses and checks from loop
+            if (action == null)
+                throw new NullPointerException();
+            if ((a = array).length >= (hi = fence) &&
+                (i = index) >= 0 && i < (index = hi)) {
+                do { action.accept(a[i]); } while (++i < hi);
+            }
+        }
+
+        public boolean tryAdvance(DoubleConsumer action) {
+            if (action == null)
+                throw new NullPointerException();
+            if (index >= 0 && index < fence) {
+                action.accept(array[index++]);
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() { return (long)(fence - index); }
+
+        public int characteristics() {
+            return characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+    }
+
+    // Iterator-based Spliterators
+
+    /**
+     * A basic Spliterator using a given Iterator for element
+     * operations. The spliterator implements {@code trySplit} to
+     * permit limited parallelism.
+     */
+    static final class IteratorSpliterator<T> implements Spliterator<T> {
+        static final int MAX_BATCH = 1 << 12;  // saturate batch size; see below
+        private final Collection<T> collection; // null OK
+        private Iterator<T> it;
+        private final int characteristics;
+        private long est;             // size estimate
+        private int batch;            // batch size for splits
+
+        /**
+         * Creates a new spliterator using the given given
+         * collection's {@link java.util.Collection#iterator()) for traversal, and
+         * reporting its {@link java.util.Collection#size()) as its initial size.
+         *
+         * @param c the collection
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public IteratorSpliterator(Collection<T> collection, int characteristics) {
+            this.collection = collection;
+            this.it = null;
+            this.characteristics = characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+
+        /**
+         * Creates a new spliterator using the given iterator
+         * for traversal, and reporting the given initial size
+         * and characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param size the number of elements in the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public IteratorSpliterator(Iterator<T> iterator, long size, int characteristics) {
+            this.collection = null;
+            this.it = iterator;
+            this.est = size;
+            this.characteristics = characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+
+        /**
+         * Creates a new spliterator using the given iterator for a
+         * source of unknown size, reporting the given
+         * characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public IteratorSpliterator(Iterator<T> iterator, int characteristics) {
+            this.collection = null;
+            this.it = iterator;
+            this.est = Long.MAX_VALUE;
+            this.characteristics = characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
+        }
+
+        public Spliterator<T> trySplit() {
+            /*
+             * Split into arrays of arithmetically increasing batch
+             * sizes, giving up at MAX_BATCH.  This will only improve
+             * parallel performance if per-element Consumer actions
+             * are more costly than transfering them into an array.
+             * The use of an arithmetic progression in split sizes
+             * provides overhead vs parallelism bounds that do not
+             * particularly favor or penalize cases of lightweight vs
+             * heavyweight element operations, across combinations of
+             * #elements vs #cores, whether or not either are known.
+             * We generate O(sqrt(#elements)) splits, allowing
+             * O(sqrt(#cores)) potential speedup. The cutoff value
+             * limits asymptotic speedups for large #elements, but is
+             * needed to limit runaway overhead impact when the cost
+             * of allocating, filling, and splitting off arrays dwarfs
+             * all other processing.
+             */
+            int n;
+            if (it == null) {
+                it = collection.iterator();
+                est = (long) collection.size();
+            }
+            if (it.hasNext() && (n = batch + 1) > 0 && n <= MAX_BATCH) {
+                Object[] a = new Object[batch = n];
+                int i = 0;
+                do { a[i++] = it.next(); } while (it.hasNext() && i < n);
+                if (est != Long.MAX_VALUE)
+                    est -= i;
+                return new ArraySpliterator<>(a, 0, i, characteristics);
+            }
+            return null;
+        }
+
+        public void forEach(Consumer<? super T> action) {
+            if (action == null) throw new NullPointerException();
+            if (it == null) {
+                it = collection.iterator();
+                est = (long)collection.size();
+            }
+            while (it.hasNext())
+                action.accept(it.next());
+        }
+
+        public boolean tryAdvance(Consumer<? super T> action) {
+            if (action == null) throw new NullPointerException();
+            if (it == null) {
+                it = collection.iterator();
+                est = (long) collection.size();
+            }
+            if (it.hasNext()) {
+                action.accept(it.next());
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() {
+            if (it == null) {
+                it = collection.iterator();
+                return est = (long)collection.size();
+            }
+            return est;
+        }
+
+        public int characteristics() { return characteristics; }
+    }
+
+    /**
+     * A basic Spliterator.OfInt using a given IntStream.IntIterator for element
+     * operations. The spliterator implements {@code trySplit} to
+     * permit limited parallelism.
+     */
+    static final class IntIteratorSpliterator implements Spliterator.OfInt {
+        private PrimitiveIterator.OfInt it;
+        private final int characteristics;
+        private long est;             // size estimate
+        private int batch;            // batch size for splits
+
+        /**
+         * Creates a new spliterator using the given iterator
+         * for traversal, and reporting the given initial size
+         * and characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param size the number of elements in the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public IntIteratorSpliterator(PrimitiveIterator.OfInt iterator, long size, int characteristics) {
+            this.it = iterator;
+            this.est = size;
+            this.characteristics = characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+
+        /**
+         * Creates a new spliterator using the given iterator for a
+         * source of unknown size, reporting the given
+         * characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public IntIteratorSpliterator(PrimitiveIterator.OfInt iterator, int characteristics) {
+            this.it = iterator;
+            this.est = Long.MAX_VALUE;
+            this.characteristics = characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
+        }
+
+        public OfInt trySplit() {
+            int n;
+            if (it.hasNext() && (n = batch + 1) > 0 && n <= IteratorSpliterator.MAX_BATCH) {
+                int[] a = new int[batch = n];
+                int i = 0;
+                do { a[i++] = it.nextInt(); } while (it.hasNext() && i < n);
+                if (est != Long.MAX_VALUE)
+                    est -= i;
+                return new IntArraySpliterator(a, 0, i, characteristics);
+            }
+            return null;
+        }
+
+        public void forEach(IntConsumer action) {
+            if (action == null) throw new NullPointerException();
+            while (it.hasNext())
+                action.accept(it.nextInt());
+        }
+
+        public boolean tryAdvance(IntConsumer action) {
+            if (action == null) throw new NullPointerException();
+            if (it.hasNext()) {
+                action.accept(it.nextInt());
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() {
+            return est;
+        }
+
+        public int characteristics() { return characteristics; }
+    }
+
+    static final class LongIteratorSpliterator implements Spliterator.OfLong {
+        private PrimitiveIterator.OfLong it;
+        private final int characteristics;
+        private long est;             // size estimate
+        private int batch;            // batch size for splits
+
+        /**
+         * Creates a new spliterator using the given iterator
+         * for traversal, and reporting the given initial size
+         * and characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param size the number of elements in the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public LongIteratorSpliterator(PrimitiveIterator.OfLong iterator, long size, int characteristics) {
+            this.it = iterator;
+            this.est = size;
+            this.characteristics = characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+
+        /**
+         * Creates a new spliterator using the given iterator for a
+         * source of unknown size, reporting the given
+         * characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public LongIteratorSpliterator(PrimitiveIterator.OfLong iterator, int characteristics) {
+            this.it = iterator;
+            this.est = Long.MAX_VALUE;
+            this.characteristics = characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
+        }
+
+        public OfLong trySplit() {
+            int n;
+            if (it.hasNext() && (n = batch + 1) > 0 && n <= IteratorSpliterator.MAX_BATCH) {
+                long[] a = new long[batch = n];
+                int i = 0;
+                do { a[i++] = it.nextLong(); } while (it.hasNext() && i < n);
+                if (est != Long.MAX_VALUE)
+                    est -= i;
+                return new LongArraySpliterator(a, 0, i, characteristics);
+            }
+            return null;
+        }
+
+        public void forEach(LongConsumer action) {
+            if (action == null) throw new NullPointerException();
+            while (it.hasNext())
+                action.accept(it.nextLong());
+        }
+
+        public boolean tryAdvance(LongConsumer action) {
+            if (action == null) throw new NullPointerException();
+            if (it.hasNext()) {
+                action.accept(it.nextLong());
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() {
+            return est;
+        }
+
+        public int characteristics() { return characteristics; }
+    }
+
+    static final class DoubleIteratorSpliterator implements Spliterator.OfDouble {
+        private PrimitiveIterator.OfDouble it;
+        private final int characteristics;
+        private long est;             // size estimate
+        private int batch;            // batch size for splits
+
+        /**
+         * Creates a new spliterator using the given iterator
+         * for traversal, and reporting the given initial size
+         * and characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param size the number of elements in the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public DoubleIteratorSpliterator(PrimitiveIterator.OfDouble iterator, long size, int characteristics) {
+            this.it = iterator;
+            this.est = size;
+            this.characteristics = characteristics | Spliterator.SIZED | Spliterator.SUBSIZED;
+        }
+
+        /**
+         * Creates a new spliterator using the given iterator for a
+         * source of unknown size, reporting the given
+         * characteristics.
+         *
+         * @param iterator the iterator for the source
+         * @param characteristics properties of this spliterator's
+         * source or elements.
+         */
+        public DoubleIteratorSpliterator(PrimitiveIterator.OfDouble iterator, int characteristics) {
+            this.it = iterator;
+            this.est = Long.MAX_VALUE;
+            this.characteristics = characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
+        }
+
+        public OfDouble trySplit() {
+            int n;
+            if (it.hasNext() && (n = batch + 1) > 0 && n <= IteratorSpliterator.MAX_BATCH) {
+                double[] a = new double[batch = n];
+                int i = 0;
+                do { a[i++] = it.nextDouble(); } while (it.hasNext() && i < n);
+                if (est != Long.MAX_VALUE)
+                    est -= i;
+                return new DoubleArraySpliterator(a, 0, i, characteristics);
+            }
+            return null;
+        }
+
+        public void forEach(DoubleConsumer action) {
+            if (action == null) throw new NullPointerException();
+            while (it.hasNext())
+                action.accept(it.nextDouble());
+        }
+
+        public boolean tryAdvance(DoubleConsumer action) {
+            if (action == null) throw new NullPointerException();
+            if (it.hasNext()) {
+                action.accept(it.nextDouble());
+                return true;
+            }
+            return false;
+        }
+
+        public long estimateSize() {
+            return est;
+        }
+
+        public int characteristics() { return characteristics; }
+    }
+}
--- a/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/ArrayBlockingQueue.java	Fri Feb 22 18:53:32 2013 +0100
@@ -5,18 +5,17 @@
  */
 
 package java.util.concurrent;
+import java.util.Spliterators;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.AbstractQueue;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.lang.ref.WeakReference;
 import java.util.Spliterator;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
-import java.util.function.Consumer;
 
 /**
  * A bounded {@linkplain BlockingQueue blocking queue} backed by an
@@ -1371,7 +1370,7 @@
     }
 
     Spliterator<E> spliterator() {
-        return Collections.iteratorBasedSpliterator
+        return Spliterators.spliterator
             (this, Spliterator.ORDERED | Spliterator.NONNULL |
              Spliterator.CONCURRENT);
     }
--- a/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/ConcurrentLinkedDeque.java	Fri Feb 22 18:53:32 2013 +0100
@@ -9,15 +9,15 @@
 import java.util.AbstractCollection;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Deque;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Queue;
 import java.util.Spliterator;
+import java.util.Spliterators;
+import java.util.function.Consumer;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
-import java.util.function.Consumer;
 
 /**
  * An unbounded concurrent {@linkplain Deque deque} based on linked nodes.
@@ -1387,7 +1387,7 @@
                 } while (p != null && i < n);
                 if ((current = p) == null)
                     exhausted = true;
-                return Collections.arraySnapshotSpliterator
+                return Spliterators.spliterator
                     (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
                      Spliterator.CONCURRENT);
             }
--- a/src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/ConcurrentLinkedQueue.java	Fri Feb 22 18:53:32 2013 +0100
@@ -36,14 +36,13 @@
 package java.util.concurrent;
 
 import java.util.AbstractQueue;
-import java.util.Arrays;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Queue;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
 import java.util.function.Consumer;
@@ -830,9 +829,9 @@
                 } while (p != null && i < n);
                 if ((current = p) == null)
                     exhausted = true;
-                return Collections.arraySnapshotSpliterator
-                    (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
-                     Spliterator.CONCURRENT);
+                return Spliterators.spliterator
+                        (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
+                                  Spliterator.CONCURRENT);
             }
             return null;
         }
--- a/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/CopyOnWriteArrayList.java	Fri Feb 22 18:53:32 2013 +0100
@@ -47,7 +47,6 @@
 import java.util.AbstractList;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.ConcurrentModificationException;
 import java.util.Iterator;
 import java.util.List;
@@ -55,6 +54,7 @@
 import java.util.NoSuchElementException;
 import java.util.RandomAccess;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
@@ -1012,16 +1012,18 @@
     }
 
     Spliterator<E> spliterator() {
-        return Collections.arraySnapshotSpliterator
-            (getArray(), Spliterator.IMMUTABLE | Spliterator.ORDERED);
+        return Spliterators.spliterator(getArray(),
+                                        Spliterator.IMMUTABLE | Spliterator.ORDERED);
     }
 
     public Stream<E> stream() {
-        return Streams.stream(spliterator());
+        return Streams.stream(() -> spliterator(),
+                              Spliterator.SIZED | Spliterator.IMMUTABLE | Spliterator.ORDERED);
+    }
 
-    }
     public Stream<E> parallelStream() {
-        return Streams.parallelStream(spliterator());
+        return Streams.parallelStream(() -> spliterator(),
+                                      Spliterator.SIZED | Spliterator.IMMUTABLE | Spliterator.ORDERED);
     }
 
     static final class COWIterator<E> implements ListIterator<E> {
@@ -1303,8 +1305,8 @@
                 throw new ConcurrentModificationException();
             if (lo < 0 || hi > a.length)
                 throw new IndexOutOfBoundsException();
-            return Collections.arraySnapshotSpliterator
-                (a, lo, hi, Spliterator.IMMUTABLE | Spliterator.ORDERED);
+            return Spliterators.spliterator
+                    (a, lo, hi, Spliterator.IMMUTABLE | Spliterator.ORDERED);
         }
 
         public Stream<E> stream() {
--- a/src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/CopyOnWriteArraySet.java	Fri Feb 22 18:53:32 2013 +0100
@@ -35,10 +35,10 @@
 
 package java.util.concurrent;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Set;
 import java.util.AbstractSet;
 import java.util.Iterator;
+import java.util.Spliterators;
 import java.util.stream.Stream;
 import java.util.Spliterator;
 import java.util.stream.Streams;
@@ -390,16 +390,20 @@
     }
 
     Spliterator<E> spliterator() {
-        return Collections.arraySnapshotSpliterator
-            (al.getArray(), Spliterator.IMMUTABLE | 
-             Spliterator.DISTINCT | Spliterator.ORDERED);
+        return Spliterators.spliterator(al.getArray(),
+                                        Spliterator.IMMUTABLE | Spliterator.DISTINCT | Spliterator.ORDERED);
     }
 
     public Stream<E> stream() {
-        return Streams.stream(spliterator());
+        return Streams.stream(() -> spliterator(),
+                              Spliterator.SIZED | Spliterator.SUBSIZED |
+                              Spliterator.IMMUTABLE | Spliterator.DISTINCT | Spliterator.ORDERED);
     }
+
     public Stream<E> parallelStream() {
-        return Streams.parallelStream(spliterator());
+        return Streams.parallelStream(() -> spliterator(),
+                                      Spliterator.SIZED | Spliterator.SUBSIZED |
+                                      Spliterator.IMMUTABLE | Spliterator.DISTINCT | Spliterator.ORDERED);
     }
 
     /**
--- a/src/share/classes/java/util/concurrent/LinkedBlockingDeque.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/LinkedBlockingDeque.java	Fri Feb 22 18:53:32 2013 +0100
@@ -37,9 +37,9 @@
 
 import java.util.AbstractQueue;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
+import java.util.Spliterators;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.Spliterator;
@@ -1211,9 +1211,9 @@
                 }
                 else if ((est -= i) <= 0L)
                     est = 1L;
-                return Collections.arraySnapshotSpliterator
-                    (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
-                     Spliterator.CONCURRENT);
+                return Spliterators.spliterator
+                        (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
+                                  Spliterator.CONCURRENT);
             }
             return null;
         }
--- a/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/LinkedBlockingQueue.java	Fri Feb 22 18:53:32 2013 +0100
@@ -35,12 +35,12 @@
 
 package java.util.concurrent;
 
+import java.util.Spliterators;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.AbstractQueue;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Spliterator;
@@ -900,9 +900,9 @@
                 }
                 else if ((est -= i) <= 0L)
                     est = 1L;
-                return Collections.arraySnapshotSpliterator
-                    (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
-                     Spliterator.CONCURRENT);
+                return Spliterators.spliterator
+                        (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
+                                  Spliterator.CONCURRENT);
             }
             return null;
         }
--- a/src/share/classes/java/util/concurrent/LinkedTransferQueue.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/LinkedTransferQueue.java	Fri Feb 22 18:53:32 2013 +0100
@@ -36,13 +36,11 @@
 package java.util.concurrent;
 
 import java.util.AbstractQueue;
-import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
 import java.util.Queue;
-import java.util.concurrent.TimeUnit;
+import java.util.Spliterators;
 import java.util.concurrent.locks.LockSupport;
 import java.util.Spliterator;
 import java.util.stream.Stream;
@@ -968,9 +966,9 @@
                 } while (p != null && i < n);
                 if ((current = p) == null)
                     exhausted = true;
-                return Collections.arraySnapshotSpliterator
-                    (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
-                     Spliterator.CONCURRENT);
+                return Spliterators.spliterator
+                        (a, 0, i, Spliterator.ORDERED | Spliterator.NONNULL |
+                                  Spliterator.CONCURRENT);
             }
             return null;
         }
--- a/src/share/classes/java/util/concurrent/PriorityBlockingQueue.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/PriorityBlockingQueue.java	Fri Feb 22 18:53:32 2013 +0100
@@ -6,12 +6,12 @@
 
 package java.util.concurrent;
 
+import java.util.Spliterators;
 import java.util.concurrent.locks.Condition;
 import java.util.concurrent.locks.ReentrantLock;
 import java.util.AbstractQueue;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.Comparator;
 import java.util.Iterator;
 import java.util.NoSuchElementException;
@@ -19,9 +19,9 @@
 import java.util.Queue;
 import java.util.SortedSet;
 import java.util.Spliterator;
+import java.util.function.Consumer;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
-import java.util.function.Consumer;
 
 /**
  * An unbounded {@linkplain BlockingQueue blocking queue} that uses
--- a/src/share/classes/java/util/concurrent/SynchronousQueue.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/concurrent/SynchronousQueue.java	Fri Feb 22 18:53:32 2013 +0100
@@ -1082,7 +1082,7 @@
     }
 
     Spliterator<E> spliterator() {
-        return Streams.emptySpliterator();
+        return Spliterators.emptySpliterator();
     }
 
     public Stream<E> stream() {
--- a/src/share/classes/java/util/stream/DoublePipeline.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/DoublePipeline.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 
 import java.util.Objects;
 import java.util.OptionalDouble;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.BooleanSupplier;
 import java.util.function.DoubleBinaryOperator;
 import java.util.function.DoubleConsumer;
@@ -83,12 +85,12 @@
 
     @Override
     protected <P_IN> Spliterator<Double> wrap(PipelineHelper<P_IN, Double> ph, Spliterator<P_IN> spliterator, boolean isParallel) {
-        return new Spliterators.DoubleWrappingSpliterator<>(ph, spliterator, isParallel);
+        return new StreamSpliterators.DoubleWrappingSpliterator<>(ph, spliterator, isParallel);
     }
 
     @Override
     protected Spliterator.OfDouble lazySpliterator(Supplier supplier) {
-        return new Spliterators.DelegatingSpliterator.OfDouble(supplier);
+        return new StreamSpliterators.DelegatingSpliterator.OfDouble(supplier);
     }
 
     @Override
@@ -136,8 +138,8 @@
     }
 
     @Override
-    public DoubleIterator iterator() {
-        return Streams.doubleIteratorFrom(spliterator());
+    public PrimitiveIterator.OfDouble iterator() {
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     // Stateless intermediate ops from DoubleStream
--- a/src/share/classes/java/util/stream/DoubleStream.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/DoubleStream.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,11 +24,8 @@
  */
 package java.util.stream;
 
-import java.util.Iterator;
-import java.util.OptionalDouble;
-import java.util.Spliterator;
+import java.util.*;
 import java.util.function.BooleanSupplier;
-import java.util.function.Consumer;
 import java.util.function.DoubleBinaryOperator;
 import java.util.function.DoubleConsumer;
 import java.util.function.DoubleFunction;
@@ -45,7 +42,7 @@
     // BaseStream
 
     @Override
-    DoubleIterator iterator();
+    PrimitiveIterator.OfDouble iterator();
 
     @Override
     Spliterator.OfDouble spliterator();
@@ -126,35 +123,4 @@
     }
 
     double[] toArray();
-
-    interface DoubleIterator extends Iterator<Double> {
-
-        @Override
-        default Double next() {
-            if (Tripwire.enabled)
-                Tripwire.trip(getClass(), "{0} using boxed double in next()");
-            return nextDouble();
-        }
-
-        double nextDouble();
-
-        @Override
-        default void forEach(Consumer<? super Double> sink) {
-            if (sink instanceof DoubleConsumer) {
-                forEachDouble((DoubleConsumer) sink);
-            }
-            else {
-                if (Tripwire.enabled)
-                    Tripwire.trip(getClass(), "{0} using boxed double in forEach()");
-                while (hasNext()) {
-                    sink.accept(nextDouble());
-                }
-            }
-        }
-
-        default void forEachDouble(DoubleConsumer block) {
-            while (hasNext())
-                block.accept(nextDouble());
-        }
-    }
 }
--- a/src/share/classes/java/util/stream/IntPipeline.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/IntPipeline.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 
 import java.util.Objects;
 import java.util.OptionalInt;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.BooleanSupplier;
 import java.util.function.IntBinaryOperator;
 import java.util.function.IntConsumer;
@@ -82,12 +84,12 @@
 
     @Override
     protected <P_IN> Spliterator<Integer> wrap(PipelineHelper<P_IN, Integer> ph, Spliterator<P_IN> spliterator, boolean isParallel) {
-        return new Spliterators.IntWrappingSpliterator<>(ph, spliterator, isParallel);
+        return new StreamSpliterators.IntWrappingSpliterator<>(ph, spliterator, isParallel);
     }
 
     @Override
     protected Spliterator.OfInt lazySpliterator(Supplier supplier) {
-        return new Spliterators.DelegatingSpliterator.OfInt(supplier);
+        return new StreamSpliterators.DelegatingSpliterator.OfInt(supplier);
     }
 
     @Override
@@ -135,8 +137,8 @@
     }
 
     @Override
-    public IntIterator iterator() {
-        return Streams.intIteratorFrom(spliterator());
+    public PrimitiveIterator.OfInt iterator() {
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     // Stateless intermediate ops from IntStream
--- a/src/share/classes/java/util/stream/IntStream.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/IntStream.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,13 +24,8 @@
  */
 package java.util.stream;
 
-import java.util.Iterator;
-import java.util.OptionalDouble;
-import java.util.OptionalInt;
-import java.util.Spliterator;
+import java.util.*;
 import java.util.function.BooleanSupplier;
-import java.util.function.Consumer;
-import java.util.function.Function;
 import java.util.function.IntBinaryOperator;
 import java.util.function.IntConsumer;
 import java.util.function.IntFunction;
@@ -52,7 +47,7 @@
 public interface IntStream extends BaseStream<Integer, IntStream> {
 
     @Override
-    IntIterator iterator();
+    PrimitiveIterator.OfInt iterator();
 
     @Override
     Spliterator.OfInt spliterator();
@@ -182,35 +177,4 @@
     }
 
     int[] toArray();
-
-    interface IntIterator extends Iterator<Integer> {
-
-        @Override
-        default Integer next() {
-            if (Tripwire.enabled)
-                Tripwire.trip(getClass(), "{0} using boxed int in next()");
-            return nextInt();
-        }
-
-        int nextInt();
-
-        @Override
-        default void forEach(Consumer<? super Integer> sink) {
-            if (sink instanceof IntConsumer) {
-                forEachInt((IntConsumer) sink);
-            }
-            else {
-                if (Tripwire.enabled)
-                    Tripwire.trip(getClass(), "{0} using boxed int in forEach()");
-                while (hasNext()) {
-                    sink.accept(nextInt());
-                }
-            }
-        }
-
-        default void forEachInt(IntConsumer block) {
-            while (hasNext())
-                block.accept(nextInt());
-        }
-    }
 }
--- a/src/share/classes/java/util/stream/LongPipeline.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/LongPipeline.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 
 import java.util.Objects;
 import java.util.OptionalLong;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.BooleanSupplier;
 import java.util.function.IntFunction;
 import java.util.function.LongBinaryOperator;
@@ -83,12 +85,12 @@
 
     @Override
     protected <P_IN> Spliterator<Long> wrap(PipelineHelper<P_IN, Long> ph, Spliterator<P_IN> spliterator, boolean isParallel) {
-        return new Spliterators.LongWrappingSpliterator<>(ph, spliterator, isParallel);
+        return new StreamSpliterators.LongWrappingSpliterator<>(ph, spliterator, isParallel);
     }
 
     @Override
     protected Spliterator.OfLong lazySpliterator(Supplier supplier) {
-        return new Spliterators.DelegatingSpliterator.OfLong(supplier);
+        return new StreamSpliterators.DelegatingSpliterator.OfLong(supplier);
     }
 
     @Override
@@ -136,8 +138,8 @@
     }
 
     @Override
-    public LongIterator iterator() {
-        return Streams.longIteratorFrom(spliterator());
+    public PrimitiveIterator.OfLong iterator() {
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     // Stateless intermediate ops from LongStream
--- a/src/share/classes/java/util/stream/LongStream.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/LongStream.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,12 +24,8 @@
  */
 package java.util.stream;
 
-import java.util.Iterator;
-import java.util.OptionalDouble;
-import java.util.OptionalLong;
-import java.util.Spliterator;
+import java.util.*;
 import java.util.function.BooleanSupplier;
-import java.util.function.Consumer;
 import java.util.function.LongBinaryOperator;
 import java.util.function.LongConsumer;
 import java.util.function.LongFunction;
@@ -46,7 +42,7 @@
     // BaseStream
 
     @Override
-    LongIterator iterator();
+    PrimitiveIterator.OfLong iterator();
 
     @Override
     Spliterator.OfLong spliterator();
@@ -129,35 +125,4 @@
     }
 
     long[] toArray();
-
-    interface LongIterator extends Iterator<Long> {
-
-        @Override
-        default Long next() {
-            if (Tripwire.enabled)
-                Tripwire.trip(getClass(), "{0} using boxed long in next()");
-            return nextLong();
-        }
-
-        long nextLong();
-
-        @Override
-        default void forEach(Consumer<? super Long> sink) {
-            if (sink instanceof LongConsumer) {
-                forEachLong((LongConsumer) sink);
-            }
-            else {
-                if (Tripwire.enabled)
-                    Tripwire.trip(getClass(), "{0} using boxed long in forEach()");
-                while (hasNext()) {
-                    sink.accept(nextLong());
-                }
-            }
-        }
-
-        default void forEachLong(LongConsumer block) {
-            while (hasNext())
-                block.accept(nextLong());
-        }
-    }
 }
--- a/src/share/classes/java/util/stream/Nodes.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/Nodes.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,13 +24,8 @@
  */
 package java.util.stream;
 
-import java.util.ArrayDeque;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Deque;
-import java.util.List;
-import java.util.Objects;
-import java.util.Spliterator;
+import java.util.*;
+import java.util.Spliterators;
 import java.util.function.Consumer;
 import java.util.function.DoubleConsumer;
 import java.util.function.IntConsumer;
@@ -634,7 +629,7 @@
     private static class EmptyNode<T> implements Node<T> {
         @Override
         public Spliterator<T> spliterator() {
-            return Streams.emptySpliterator();
+            return Spliterators.emptySpliterator();
         }
 
         @Override
@@ -1251,7 +1246,7 @@
     private static class EmptyIntNode extends EmptyNode<Integer> implements Node.OfInt {
         @Override
         public Spliterator.OfInt spliterator() {
-            return Streams.emptyIntSpliterator();
+            return Spliterators.emptyIntSpliterator();
         }
 
         @Override
@@ -1269,7 +1264,7 @@
     private static class EmptyLongNode extends EmptyNode<Long> implements Node.OfLong {
         @Override
         public Spliterator.OfLong spliterator() {
-            return Streams.emptyLongSpliterator();
+            return Spliterators.emptyLongSpliterator();
         }
 
         @Override
@@ -1287,7 +1282,7 @@
     private static class EmptyDoubleNode extends EmptyNode<Double> implements Node.OfDouble {
         @Override
         public Spliterator.OfDouble spliterator() {
-            return Streams.emptyDoubleSpliterator();
+            return Spliterators.emptyDoubleSpliterator();
         }
 
         @Override
--- a/src/share/classes/java/util/stream/ReferencePipeline.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/ReferencePipeline.java	Fri Feb 22 18:53:32 2013 +0100
@@ -29,6 +29,7 @@
 import java.util.Objects;
 import java.util.Optional;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.BiConsumer;
 import java.util.function.BiFunction;
 import java.util.function.BinaryOperator;
@@ -92,12 +93,12 @@
 
     @Override
     protected <P_IN> Spliterator<U> wrap(PipelineHelper<P_IN, U> ph, Spliterator<P_IN> spliterator, boolean isParallel) {
-        return new Spliterators.WrappingSpliterator<>(ph, spliterator, isParallel);
+        return new StreamSpliterators.WrappingSpliterator<>(ph, spliterator, isParallel);
     }
 
     @Override
     protected Spliterator<U> lazySpliterator(Supplier<Spliterator<U>> supplier) {
-        return new Spliterators.DelegatingSpliterator<>(supplier);
+        return new StreamSpliterators.DelegatingSpliterator<>(supplier);
     }
 
     @Override
@@ -117,7 +118,7 @@
 
     @Override
     public Iterator<U> iterator() {
-        return Streams.iteratorFrom(spliterator());
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     // Stateless intermediate operations from Stream
--- a/src/share/classes/java/util/stream/SpinedBuffer.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/SpinedBuffer.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,11 +24,8 @@
  */
 package java.util.stream;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Spliterator;
+import java.util.*;
+import java.util.Spliterators;
 import java.util.function.Consumer;
 import java.util.function.DoubleConsumer;
 import java.util.function.IntConsumer;
@@ -218,7 +215,7 @@
 
     @Override
     public Iterator<E> iterator() {
-        return Streams.iteratorFrom(spliterator());
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     @Override
@@ -678,8 +675,8 @@
         }
 
         @Override
-        public IntStream.IntIterator iterator() {
-            return Streams.intIteratorFrom(spliterator());
+        public PrimitiveIterator.OfInt iterator() {
+            return Spliterators.iteratorFromSpliterator(spliterator());
         }
 
         private class Splitr
@@ -778,8 +775,8 @@
         }
 
         @Override
-        public LongStream.LongIterator iterator() {
-            return Streams.longIteratorFrom(spliterator());
+        public PrimitiveIterator.OfLong iterator() {
+            return Spliterators.iteratorFromSpliterator(spliterator());
         }
 
         private class Splitr
@@ -877,8 +874,8 @@
         }
 
         @Override
-        public DoubleStream.DoubleIterator iterator() {
-            return Streams.doubleIteratorFrom(spliterator());
+        public PrimitiveIterator.OfDouble iterator() {
+            return Spliterators.iteratorFromSpliterator(spliterator());
         }
 
         private class Splitr
--- a/src/share/classes/java/util/stream/Spliterators.java	Fri Feb 22 18:41:13 2013 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,679 +0,0 @@
-/*
- * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-package java.util.stream;
-
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.Objects;
-import java.util.Spliterator;
-import java.util.function.BooleanSupplier;
-import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
-import java.util.function.IntConsumer;
-import java.util.function.LongConsumer;
-import java.util.function.Supplier;
-
-/**
- * Spliterators
- *
- * @since 1.8
- */
-public class Spliterators {
-
-    static abstract class AbstractWrappingSpliterator<P_IN, P_OUT, T_BUFFER extends AbstractSpinedBuffer<P_OUT>>
-            implements Spliterator<P_OUT> {
-        // True if this spliterator supports splitting
-        protected final boolean isParallel;
-
-        protected final PipelineHelper<P_IN, P_OUT> ph;
-
-        // The source spliterator whose elements are traversed and pushed through bufferSink
-        protected final Spliterator<P_IN> spliterator;
-
-        // The source of the sink chain for the pipeline where the last sink
-        // is connected to buffer
-        // null if no partial traverse has occurred
-        protected Sink<P_IN> bufferSink;
-
-        // When invoked advances one element of spliterator pushing that element through
-        // bufferSink and returns true, otherwise returns false if the are no more elements
-        // of the spliterator to traverse
-        // null if no partial traverse has occurred
-        protected BooleanSupplier pusher;
-
-        // The next element to consume from buffer
-        // Used only for partial traversal
-        protected long nextToConsume;
-
-        // The buffer to push elements to when partially traversing with tryAdvance
-        // null if no partial traverse has occurred
-        protected T_BUFFER buffer;
-
-        // True if full traversal of the source spliterator (with possible cancellation) has occurred
-        // When buffer is not null there still may be elements in the buffer to be consumed
-        protected boolean finished;
-
-        private AbstractWrappingSpliterator(PipelineHelper<P_IN, P_OUT> ph, Spliterator<P_IN> spliterator, boolean parallel) {
-            this.spliterator = spliterator;
-            this.ph = ph;
-            this.isParallel = parallel;
-        }
-
-        protected boolean doAdvance() {
-            if (buffer == null) {
-                if (finished)
-                    return false;
-
-                initPartialTraversalState();
-                nextToConsume = 0;
-                bufferSink.begin(spliterator.getExactSizeIfKnown());
-                return fillBuffer();
-            }
-            else {
-                ++nextToConsume;
-                boolean hasNext = nextToConsume < buffer.count();
-                if (!hasNext) {
-                    nextToConsume = 0;
-                    buffer.clear();
-                    hasNext = fillBuffer();
-                }
-                return hasNext;
-            }
-        }
-
-        protected abstract AbstractWrappingSpliterator<P_IN, P_OUT, ?> wrap(Spliterator<P_IN> s);
-
-        protected abstract void initPartialTraversalState();
-
-        @Override
-        public Spliterator<P_OUT> trySplit() {
-            if (isParallel && !finished) {
-                Spliterator<P_IN> split = spliterator.trySplit();
-                return (split == null) ? null : wrap(split);
-            }
-            else
-                return null;
-        }
-
-        private boolean fillBuffer() {
-            while (buffer.count() == 0) {
-                if (bufferSink.cancellationRequested() || !pusher.getAsBoolean()) {
-                    if (finished)
-                        return false;
-                    else {
-                        bufferSink.end(); // might trigger more elements
-                        finished = true;
-                    }
-                }
-            }
-            return true;
-        }
-
-        @Override
-        public long estimateSize() {
-            return StreamOpFlag.SIZED.isKnown(ph.getStreamAndOpFlags()) ? spliterator.estimateSize() : Long.MAX_VALUE;
-        }
-
-        @Override
-        public long getExactSizeIfKnown() {
-            return StreamOpFlag.SIZED.isKnown(ph.getStreamAndOpFlags()) ? spliterator.getExactSizeIfKnown() : -1;
-        }
-
-        @Override
-        public int characteristics() {
-            // Get the characteristics from the pipeline
-            int c = StreamOpFlag.toCharacteristics(StreamOpFlag.toStreamFlags(ph.getStreamAndOpFlags()));
-
-            // Mask off the size and uniform characteristics and replace with those of the spliterator
-            // Note that a non-uniform spliterator can change from something with an exact size to an
-            // estimate for a sub-split, for example with HashSet where the size is known at the top
-            // level spliterator but for sub-splits only an estimate is known
-            if ((c & Spliterator.SIZED) != 0) {
-                c &= ~(Spliterator.SIZED | Spliterator.SUBSIZED);
-                c |= (spliterator.characteristics() & Spliterator.SIZED & Spliterator.SUBSIZED);
-            }
-
-            return c;
-        }
-
-        @Override
-        public String toString() {
-            return getClass().getName() + "[" + spliterator + "]";
-        }
-    }
-
-    static class WrappingSpliterator<P_IN, P_OUT>
-            extends AbstractWrappingSpliterator<P_IN, P_OUT, SpinedBuffer<P_OUT>> {
-
-        WrappingSpliterator(PipelineHelper<P_IN, P_OUT> ph, Spliterator<P_IN> spliterator, boolean parallel) {
-            super(ph, spliterator, parallel);
-        }
-
-        @Override
-        protected WrappingSpliterator<P_IN, P_OUT> wrap(Spliterator<P_IN> s) {
-            return new WrappingSpliterator<>(ph, s, isParallel);
-        }
-
-        @Override
-        protected void initPartialTraversalState() {
-            SpinedBuffer<P_OUT> b = new SpinedBuffer<>();
-            buffer = b;
-            bufferSink = ph.wrapSink(b::accept);
-            pusher = () -> spliterator.tryAdvance(bufferSink);
-        }
-
-        @Override
-        public boolean tryAdvance(Consumer<? super P_OUT> consumer) {
-            boolean hasNext = doAdvance();
-            if (hasNext)
-                consumer.accept(buffer.get(nextToConsume));
-            return hasNext;
-        }
-
-        @Override
-        public void forEach(Consumer<? super P_OUT> consumer) {
-            if (buffer == null && !finished) {
-                ph.into((Sink<P_OUT>) consumer::accept, spliterator);
-                finished = true;
-            }
-            else {
-                while(tryAdvance(consumer)) { }
-            }
-        }
-    }
-
-    static class IntWrappingSpliterator<P_IN>
-            extends AbstractWrappingSpliterator<P_IN, Integer, SpinedBuffer.OfInt>
-            implements Spliterator.OfInt {
-
-        IntWrappingSpliterator(PipelineHelper<P_IN, Integer> ph, Spliterator<P_IN> spliterator, boolean parallel) {
-            super(ph, spliterator, parallel);
-        }
-
-        @Override
-        protected AbstractWrappingSpliterator<P_IN, Integer, ?> wrap(Spliterator<P_IN> s) {
-            return new IntWrappingSpliterator<>(ph, s, isParallel);
-        }
-
-        @Override
-        protected void initPartialTraversalState() {
-            SpinedBuffer.OfInt b = new SpinedBuffer.OfInt();
-            buffer = b;
-            bufferSink = ph.wrapSink((Sink.OfInt) b::accept);
-            pusher = () -> spliterator.tryAdvance(bufferSink);
-        }
-
-        @Override
-        public Spliterator.OfInt trySplit() {
-            return (Spliterator.OfInt) super.trySplit();
-        }
-
-        @Override
-        public boolean tryAdvance(IntConsumer consumer) {
-            boolean hasNext = doAdvance();
-            if (hasNext)
-                consumer.accept(buffer.get(nextToConsume));
-            return hasNext;
-        }
-
-        @Override
-        public void forEach(IntConsumer consumer) {
-            if (buffer == null && !finished) {
-                ph.into((Sink.OfInt) consumer::accept, spliterator);
-                finished = true;
-            }
-            else {
-                while(tryAdvance(consumer));
-            }
-        }
-    }
-
-    static class LongWrappingSpliterator<P_IN>
-            extends AbstractWrappingSpliterator<P_IN, Long, SpinedBuffer.OfLong>
-            implements Spliterator.OfLong {
-
-        LongWrappingSpliterator(PipelineHelper<P_IN, Long> ph, Spliterator<P_IN> spliterator, boolean parallel) {
-            super(ph, spliterator, parallel);
-        }
-
-        @Override
-        protected AbstractWrappingSpliterator<P_IN, Long, ?> wrap(Spliterator<P_IN> s) {
-            return new LongWrappingSpliterator<>(ph, s, isParallel);
-        }
-
-        @Override
-        protected void initPartialTraversalState() {
-            SpinedBuffer.OfLong b = new SpinedBuffer.OfLong();
-            buffer = b;
-            bufferSink = ph.wrapSink((Sink.OfLong) b::accept);
-            pusher = () -> spliterator.tryAdvance(bufferSink);
-        }
-
-        @Override
-        public Spliterator.OfLong trySplit() {
-            return (Spliterator.OfLong) super.trySplit();
-        }
-
-        @Override
-        public boolean tryAdvance(LongConsumer consumer) {
-            boolean hasNext = doAdvance();
-            if (hasNext)
-                consumer.accept(buffer.get(nextToConsume));
-            return hasNext;
-        }
-
-        @Override
-        public void forEach(LongConsumer consumer) {
-            if (buffer == null && !finished) {
-                ph.into((Sink.OfLong) consumer::accept, spliterator);
-                finished = true;
-            }
-            else {
-                while(tryAdvance(consumer));
-            }
-        }
-    }
-
-    static class DoubleWrappingSpliterator<P_IN>
-            extends AbstractWrappingSpliterator<P_IN, Double, SpinedBuffer.OfDouble>
-            implements Spliterator.OfDouble {
-
-        DoubleWrappingSpliterator(PipelineHelper<P_IN, Double> ph, Spliterator<P_IN> spliterator, boolean parallel) {
-            super(ph, spliterator, parallel);
-        }
-
-        @Override
-        protected AbstractWrappingSpliterator<P_IN, Double, ?> wrap(Spliterator<P_IN> s) {
-            return new DoubleWrappingSpliterator<>(ph, s, isParallel);
-        }
-
-        @Override
-        protected void initPartialTraversalState() {
-            SpinedBuffer.OfDouble b = new SpinedBuffer.OfDouble();
-            buffer = b;
-            bufferSink = ph.wrapSink((Sink.OfDouble) b::accept);
-            pusher = () -> spliterator.tryAdvance(bufferSink);
-        }
-
-        @Override
-        public Spliterator.OfDouble trySplit() {
-            return (Spliterator.OfDouble) super.trySplit();
-        }
-
-        @Override
-        public boolean tryAdvance(DoubleConsumer consumer) {
-            boolean hasNext = doAdvance();
-            if (hasNext)
-                consumer.accept(buffer.get(nextToConsume));
-            return hasNext;
-        }
-
-        @Override
-        public void forEach(DoubleConsumer consumer) {
-            if (buffer == null && !finished) {
-                ph.into((Sink.OfDouble) consumer::accept, spliterator);
-                finished = true;
-            }
-            else {
-                while(tryAdvance(consumer));
-            }
-        }
-    }
-
-    static class DelegatingSpliterator<T> implements Spliterator<T> {
-        private final Supplier<Spliterator<T>> supplier;
-
-        private Spliterator<T> s;
-
-        @SuppressWarnings("unchecked")
-        public DelegatingSpliterator(Supplier<? extends Spliterator<T>> supplier) {
-            this.supplier = (Supplier<Spliterator<T>>) supplier;
-        }
-
-        Spliterator<T> get() {
-            if (s == null) {
-                s = supplier.get();
-            }
-            return s;
-        }
-
-        @Override
-        public Spliterator<T> trySplit() {
-            return get().trySplit();
-        }
-
-        @Override
-        public boolean tryAdvance(Consumer<? super T> consumer) {
-            return get().tryAdvance(consumer);
-        }
-
-        @Override
-        public void forEach(Consumer<? super T> consumer) {
-            get().forEach(consumer);
-        }
-
-        @Override
-        public long estimateSize() {
-            return get().estimateSize();
-        }
-
-        @Override
-        public int characteristics() {
-            return get().characteristics();
-        }
-
-        @Override
-        public Comparator<? super T> getComparator() {
-            return get().getComparator();
-        }
-
-        @Override
-        public long getExactSizeIfKnown() {
-            return get().getExactSizeIfKnown();
-        }
-
-        @Override
-        public String toString() {
-            return getClass().getName() + "[" + get() + "]";
-        }
-
-        public static class OfInt extends DelegatingSpliterator<Integer> implements Spliterator.OfInt {
-
-            private Spliterator.OfInt s;
-
-            public OfInt(Supplier<Spliterator.OfInt> supplier) {
-                super(supplier);
-            }
-
-            @Override
-            Spliterator.OfInt get() {
-                if (s == null) {
-                    s = (Spliterator.OfInt) super.get();
-                }
-                return s;
-            }
-
-            @Override
-            public Spliterator.OfInt trySplit() {
-                return get().trySplit();
-            }
-
-            @Override
-            public boolean tryAdvance(IntConsumer consumer) {
-                return get().tryAdvance(consumer);
-            }
-
-            @Override
-            public void forEach(IntConsumer consumer) {
-                get().forEach(consumer);
-            }
-        }
-
-        public static class OfLong extends DelegatingSpliterator<Long> implements Spliterator.OfLong {
-
-            Spliterator.OfLong s;
-
-            public OfLong(Supplier<Spliterator.OfLong> supplier) {
-                super(supplier);
-            }
-
-            @Override
-            Spliterator.OfLong get() {
-                if (s == null) {
-                    s = (Spliterator.OfLong) super.get();
-                }
-                return s;
-            }
-
-            @Override
-            public Spliterator.OfLong trySplit() {
-                return get().trySplit();
-            }
-
-            @Override
-            public boolean tryAdvance(LongConsumer consumer) {
-                return get().tryAdvance(consumer);
-            }
-
-            @Override
-            public void forEach(LongConsumer consumer) {
-                get().forEach(consumer);
-            }
-        }
-
-        public static class OfDouble extends DelegatingSpliterator<Double> implements Spliterator.OfDouble {
-
-            Spliterator.OfDouble s;
-
-            public OfDouble(Supplier<Spliterator.OfDouble> supplier) {
-                super(supplier);
-            }
-
-            @Override
-            Spliterator.OfDouble get() {
-                if (s == null) {
-                    s = (Spliterator.OfDouble) super.get();
-                }
-                return s;
-            }
-
-            @Override
-            public Spliterator.OfDouble trySplit() {
-                return get().trySplit();
-            }
-
-            @Override
-            public boolean tryAdvance(DoubleConsumer consumer) {
-                return get().tryAdvance(consumer);
-            }
-
-            @Override
-            public void forEach(DoubleConsumer consumer) {
-                get().forEach(consumer);
-            }
-        }
-    }
-
-
-    private static abstract class AbstractArraySpliterator<T> implements Spliterator<T> {
-        // The current inclusive offset into the array
-        protected int curOffset;
-        // The exclusive end offset into the array
-        protected final int endOffset;
-
-        // When curOffset >= endOffset then this spliterator is fully traversed
-
-        private AbstractArraySpliterator(int offset, int length) {
-            this.curOffset = offset;
-            this.endOffset = offset + length;
-        }
-
-        @Override
-        public long estimateSize() {
-            return endOffset - curOffset;
-        }
-
-        @Override
-        public int characteristics() {
-            return Spliterator.ORDERED | Spliterator.SIZED | Spliterator.SUBSIZED;
-        }
-    }
-
-    public static class ArraySpliterator<T> extends AbstractArraySpliterator<T> {
-        private final T[] elements;
-
-        public ArraySpliterator(T[] elements, int offset, int length) {
-            super(offset, length);
-            Arrays.checkOffsetLenBounds(elements.length, offset, length);
-            this.elements = Objects.requireNonNull(elements);
-        }
-
-        @Override
-        public boolean tryAdvance(Consumer<? super T> consumer) {
-            if (curOffset < endOffset) {
-                consumer.accept(elements[curOffset++]);
-                return true;
-            }
-            return false;
-        }
-
-        @Override
-        public void forEach(Consumer<? super T> consumer) {
-            int hEndOffset = endOffset;
-            for (int i = curOffset; i < hEndOffset; i++)
-                consumer.accept(elements[i]);
-            curOffset = endOffset; // update only once -- reduce heap write traffic
-        }
-
-        @Override
-        public Spliterator<T> trySplit() {
-            int t = (endOffset - curOffset) / 2;
-            if (t == 0)
-                return null;
-            else {
-                Spliterator<T> ret = new ArraySpliterator<>(elements, curOffset, t);
-                curOffset += t;
-                return ret;
-            }
-        }
-    }
-
-    public static class IntArraySpliterator
-            extends AbstractArraySpliterator<Integer> implements Spliterator.OfInt {
-        private final int[] elements;
-
-        public IntArraySpliterator(int[] elements, int offset, int length) {
-            super(offset, length);
-            this.elements = Objects.requireNonNull(elements);
-        }
-
-        @Override
-        public boolean tryAdvance(IntConsumer consumer) {
-            if (curOffset < endOffset) {
-                consumer.accept(elements[curOffset++]);
-                return true;
-            }
-            return false;
-        }
-
-        @Override
-        public void forEach(IntConsumer consumer) {
-            int hEndOffset = endOffset;
-            for (int i = curOffset; i < hEndOffset; i++)
-                consumer.accept(elements[i]);
-            curOffset = endOffset; // update only once -- reduce heap write traffic
-        }
-
-        @Override
-        public OfInt trySplit() {
-            int t = (endOffset - curOffset) / 2;
-            if (t == 0)
-                return null;
-            else {
-                OfInt ret = new IntArraySpliterator(elements, curOffset, t);
-                curOffset += t;
-                return ret;
-            }
-        }
-    }
-
-    public static class LongArraySpliterator
-            extends AbstractArraySpliterator<Long> implements Spliterator.OfLong {
-        private final long[] elements;
-
-        public LongArraySpliterator(long[] elements, int offset, int length) {
-            super(offset, length);
-            this.elements = Objects.requireNonNull(elements);
-        }
-
-        @Override
-        public boolean tryAdvance(LongConsumer consumer) {
-            if (curOffset < endOffset) {
-                consumer.accept(elements[curOffset++]);
-                return true;
-            }
-            return false;
-        }
-
-        @Override
-        public void forEach(LongConsumer consumer) {
-            int hEndOffset = endOffset;
-            for (int i = curOffset; i < hEndOffset; i++)
-                consumer.accept(elements[i]);
-            curOffset = endOffset; // update only once -- reduce heap write traffic
-        }
-
-        @Override
-        public OfLong trySplit() {
-            int t = (endOffset - curOffset) / 2;
-            if (t == 0)
-                return null;
-            else {
-                OfLong ret = new LongArraySpliterator(elements, curOffset, t);
-                curOffset += t;
-                return ret;
-            }
-        }
-    }
-
-    public static class DoubleArraySpliterator
-            extends AbstractArraySpliterator<Double> implements Spliterator.OfDouble {
-        private final double[] elements;
-
-        public DoubleArraySpliterator(double[] elements, int offset, int length) {
-            super(offset, length);
-            this.elements = Objects.requireNonNull(elements);
-        }
-
-        @Override
-        public boolean tryAdvance(DoubleConsumer consumer) {
-            if (curOffset < endOffset) {
-                consumer.accept(elements[curOffset++]);
-                return true;
-            }
-            return false;
-        }
-
-        @Override
-        public void forEach(DoubleConsumer consumer) {
-            int hEndOffset = endOffset;
-            for (int i = curOffset; i < hEndOffset; i++)
-                consumer.accept(elements[i]);
-            curOffset = endOffset; // update only once -- reduce heap write traffic
-        }
-
-        @Override
-        public OfDouble trySplit() {
-            int t = (endOffset - curOffset) / 2;
-            if (t == 0)
-                return null;
-            else {
-                OfDouble ret = new DoubleArraySpliterator(elements, curOffset, t);
-                curOffset += t;
-                return ret;
-            }
-        }
-    }
-}
--- a/src/share/classes/java/util/stream/Stream.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/Stream.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,10 +24,7 @@
  */
 package java.util.stream;
 
-import java.util.Comparator;
-import java.util.Comparators;
-import java.util.Iterator;
-import java.util.Optional;
+import java.util.*;
 import java.util.function.BiConsumer;
 import java.util.function.BiFunction;
 import java.util.function.BinaryOperator;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/share/classes/java/util/stream/StreamSpliterators.java	Fri Feb 22 18:53:32 2013 +0100
@@ -0,0 +1,496 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package java.util.stream;
+
+import java.util.Comparator;
+import java.util.Spliterator;
+import java.util.function.BooleanSupplier;
+import java.util.function.Consumer;
+import java.util.function.DoubleConsumer;
+import java.util.function.IntConsumer;
+import java.util.function.LongConsumer;
+import java.util.function.Supplier;
+
+/**
+ * Spliterator classes specific to streams.
+ *
+ * @since 1.8
+ */
+class StreamSpliterators {
+
+    static abstract class AbstractWrappingSpliterator<P_IN, P_OUT, T_BUFFER extends AbstractSpinedBuffer<P_OUT>>
+            implements Spliterator<P_OUT> {
+        // True if this spliterator supports splitting
+        protected final boolean isParallel;
+
+        protected final PipelineHelper<P_IN, P_OUT> ph;
+
+        // The source spliterator whose elements are traversed and pushed through bufferSink
+        protected final Spliterator<P_IN> spliterator;
+
+        // The source of the sink chain for the pipeline where the last sink
+        // is connected to buffer
+        // null if no partial traverse has occurred
+        protected Sink<P_IN> bufferSink;
+
+        // When invoked advances one element of spliterator pushing that element through
+        // bufferSink and returns true, otherwise returns false if the are no more elements
+        // of the spliterator to traverse
+        // null if no partial traverse has occurred
+        protected BooleanSupplier pusher;
+
+        // The next element to consume from buffer
+        // Used only for partial traversal
+        protected long nextToConsume;
+
+        // The buffer to push elements to when partially traversing with tryAdvance
+        // null if no partial traverse has occurred
+        protected T_BUFFER buffer;
+
+        // True if full traversal of the source spliterator (with possible cancellation) has occurred
+        // When buffer is not null there still may be elements in the buffer to be consumed
+        protected boolean finished;
+
+        private AbstractWrappingSpliterator(PipelineHelper<P_IN, P_OUT> ph, Spliterator<P_IN> spliterator, boolean parallel) {
+            this.spliterator = spliterator;
+            this.ph = ph;
+            this.isParallel = parallel;
+        }
+
+        protected boolean doAdvance() {
+            if (buffer == null) {
+                if (finished)
+                    return false;
+
+                initPartialTraversalState();
+                nextToConsume = 0;
+                bufferSink.begin(spliterator.getExactSizeIfKnown());
+                return fillBuffer();
+            }
+            else {
+                ++nextToConsume;
+                boolean hasNext = nextToConsume < buffer.count();
+                if (!hasNext) {
+                    nextToConsume = 0;
+                    buffer.clear();
+                    hasNext = fillBuffer();
+                }
+                return hasNext;
+            }
+        }
+
+        protected abstract AbstractWrappingSpliterator<P_IN, P_OUT, ?> wrap(Spliterator<P_IN> s);
+
+        protected abstract void initPartialTraversalState();
+
+        @Override
+        public Spliterator<P_OUT> trySplit() {
+            if (isParallel && !finished) {
+                Spliterator<P_IN> split = spliterator.trySplit();
+                return (split == null) ? null : wrap(split);
+            }
+            else
+                return null;
+        }
+
+        private boolean fillBuffer() {
+            while (buffer.count() == 0) {
+                if (bufferSink.cancellationRequested() || !pusher.getAsBoolean()) {
+                    if (finished)
+                        return false;
+                    else {
+                        bufferSink.end(); // might trigger more elements
+                        finished = true;
+                    }
+                }
+            }
+            return true;
+        }
+
+        @Override
+        public long estimateSize() {
+            return StreamOpFlag.SIZED.isKnown(ph.getStreamAndOpFlags()) ? spliterator.estimateSize() : Long.MAX_VALUE;
+        }
+
+        @Override
+        public long getExactSizeIfKnown() {
+            return StreamOpFlag.SIZED.isKnown(ph.getStreamAndOpFlags()) ? spliterator.getExactSizeIfKnown() : -1;
+        }
+
+        @Override
+        public int characteristics() {
+            // Get the characteristics from the pipeline
+            int c = StreamOpFlag.toCharacteristics(StreamOpFlag.toStreamFlags(ph.getStreamAndOpFlags()));
+
+            // Mask off the size and uniform characteristics and replace with those of the spliterator
+            // Note that a non-uniform spliterator can change from something with an exact size to an
+            // estimate for a sub-split, for example with HashSet where the size is known at the top
+            // level spliterator but for sub-splits only an estimate is known
+            if ((c & Spliterator.SIZED) != 0) {
+                c &= ~(Spliterator.SIZED | Spliterator.SUBSIZED);
+                c |= (spliterator.characteristics() & Spliterator.SIZED & Spliterator.SUBSIZED);
+            }
+
+            return c;
+        }
+
+        @Override
+        public String toString() {
+            return getClass().getName() + "[" + spliterator + "]";
+        }
+    }
+
+    static class WrappingSpliterator<P_IN, P_OUT>
+            extends AbstractWrappingSpliterator<P_IN, P_OUT, SpinedBuffer<P_OUT>> {
+
+        WrappingSpliterator(PipelineHelper<P_IN, P_OUT> ph, Spliterator<P_IN> spliterator, boolean parallel) {
+            super(ph, spliterator, parallel);
+        }
+
+        @Override
+        protected WrappingSpliterator<P_IN, P_OUT> wrap(Spliterator<P_IN> s) {
+            return new WrappingSpliterator<>(ph, s, isParallel);
+        }
+
+        @Override
+        protected void initPartialTraversalState() {
+            SpinedBuffer<P_OUT> b = new SpinedBuffer<>();
+            buffer = b;
+            bufferSink = ph.wrapSink(b::accept);
+            pusher = () -> spliterator.tryAdvance(bufferSink);
+        }
+
+        @Override
+        public boolean tryAdvance(Consumer<? super P_OUT> consumer) {
+            boolean hasNext = doAdvance();
+            if (hasNext)
+                consumer.accept(buffer.get(nextToConsume));
+            return hasNext;
+        }
+
+        @Override
+        public void forEach(Consumer<? super P_OUT> consumer) {
+            if (buffer == null && !finished) {
+                ph.into((Sink<P_OUT>) consumer::accept, spliterator);
+                finished = true;
+            }
+            else {
+                while(tryAdvance(consumer)) { }
+            }
+        }
+    }
+
+    static class IntWrappingSpliterator<P_IN>
+            extends AbstractWrappingSpliterator<P_IN, Integer, SpinedBuffer.OfInt>
+            implements Spliterator.OfInt {
+
+        IntWrappingSpliterator(PipelineHelper<P_IN, Integer> ph, Spliterator<P_IN> spliterator, boolean parallel) {
+            super(ph, spliterator, parallel);
+        }
+
+        @Override
+        protected AbstractWrappingSpliterator<P_IN, Integer, ?> wrap(Spliterator<P_IN> s) {
+            return new IntWrappingSpliterator<>(ph, s, isParallel);
+        }
+
+        @Override
+        protected void initPartialTraversalState() {
+            SpinedBuffer.OfInt b = new SpinedBuffer.OfInt();
+            buffer = b;
+            bufferSink = ph.wrapSink((Sink.OfInt) b::accept);
+            pusher = () -> spliterator.tryAdvance(bufferSink);
+        }
+
+        @Override
+        public Spliterator.OfInt trySplit() {
+            return (Spliterator.OfInt) super.trySplit();
+        }
+
+        @Override
+        public boolean tryAdvance(IntConsumer consumer) {
+            boolean hasNext = doAdvance();
+            if (hasNext)
+                consumer.accept(buffer.get(nextToConsume));
+            return hasNext;
+        }
+
+        @Override
+        public void forEach(IntConsumer consumer) {
+            if (buffer == null && !finished) {
+                ph.into((Sink.OfInt) consumer::accept, spliterator);
+                finished = true;
+            }
+            else {
+                while(tryAdvance(consumer));
+            }
+        }
+    }
+
+    static class LongWrappingSpliterator<P_IN>
+            extends AbstractWrappingSpliterator<P_IN, Long, SpinedBuffer.OfLong>
+            implements Spliterator.OfLong {
+
+        LongWrappingSpliterator(PipelineHelper<P_IN, Long> ph, Spliterator<P_IN> spliterator, boolean parallel) {
+            super(ph, spliterator, parallel);
+        }
+
+        @Override
+        protected AbstractWrappingSpliterator<P_IN, Long, ?> wrap(Spliterator<P_IN> s) {
+            return new LongWrappingSpliterator<>(ph, s, isParallel);
+        }
+
+        @Override
+        protected void initPartialTraversalState() {
+            SpinedBuffer.OfLong b = new SpinedBuffer.OfLong();
+            buffer = b;
+            bufferSink = ph.wrapSink((Sink.OfLong) b::accept);
+            pusher = () -> spliterator.tryAdvance(bufferSink);
+        }
+
+        @Override
+        public Spliterator.OfLong trySplit() {
+            return (Spliterator.OfLong) super.trySplit();
+        }
+
+        @Override
+        public boolean tryAdvance(LongConsumer consumer) {
+            boolean hasNext = doAdvance();
+            if (hasNext)
+                consumer.accept(buffer.get(nextToConsume));
+            return hasNext;
+        }
+
+        @Override
+        public void forEach(LongConsumer consumer) {
+            if (buffer == null && !finished) {
+                ph.into((Sink.OfLong) consumer::accept, spliterator);
+                finished = true;
+            }
+            else {
+                while(tryAdvance(consumer));
+            }
+        }
+    }
+
+    static class DoubleWrappingSpliterator<P_IN>
+            extends AbstractWrappingSpliterator<P_IN, Double, SpinedBuffer.OfDouble>
+            implements Spliterator.OfDouble {
+
+        DoubleWrappingSpliterator(PipelineHelper<P_IN, Double> ph, Spliterator<P_IN> spliterator, boolean parallel) {
+            super(ph, spliterator, parallel);
+        }
+
+        @Override
+        protected AbstractWrappingSpliterator<P_IN, Double, ?> wrap(Spliterator<P_IN> s) {
+            return new DoubleWrappingSpliterator<>(ph, s, isParallel);
+        }
+
+        @Override
+        protected void initPartialTraversalState() {
+            SpinedBuffer.OfDouble b = new SpinedBuffer.OfDouble();
+            buffer = b;
+            bufferSink = ph.wrapSink((Sink.OfDouble) b::accept);
+            pusher = () -> spliterator.tryAdvance(bufferSink);
+        }
+
+        @Override
+        public Spliterator.OfDouble trySplit() {
+            return (Spliterator.OfDouble) super.trySplit();
+        }
+
+        @Override
+        public boolean tryAdvance(DoubleConsumer consumer) {
+            boolean hasNext = doAdvance();
+            if (hasNext)
+                consumer.accept(buffer.get(nextToConsume));
+            return hasNext;
+        }
+
+        @Override
+        public void forEach(DoubleConsumer consumer) {
+            if (buffer == null && !finished) {
+                ph.into((Sink.OfDouble) consumer::accept, spliterator);
+                finished = true;
+            }
+            else {
+                while(tryAdvance(consumer));
+            }
+        }
+    }
+
+    static class DelegatingSpliterator<T> implements Spliterator<T> {
+        private final Supplier<Spliterator<T>> supplier;
+
+        private Spliterator<T> s;
+
+        @SuppressWarnings("unchecked")
+        public DelegatingSpliterator(Supplier<? extends Spliterator<T>> supplier) {
+            this.supplier = (Supplier<Spliterator<T>>) supplier;
+        }
+
+        Spliterator<T> get() {
+            if (s == null) {
+                s = supplier.get();
+            }
+            return s;
+        }
+
+        @Override
+        public Spliterator<T> trySplit() {
+            return get().trySplit();
+        }
+
+        @Override
+        public boolean tryAdvance(Consumer<? super T> consumer) {
+            return get().tryAdvance(consumer);
+        }
+
+        @Override
+        public void forEach(Consumer<? super T> consumer) {
+            get().forEach(consumer);
+        }
+
+        @Override
+        public long estimateSize() {
+            return get().estimateSize();
+        }
+
+        @Override
+        public int characteristics() {
+            return get().characteristics();
+        }
+
+        @Override
+        public Comparator<? super T> getComparator() {
+            return get().getComparator();
+        }
+
+        @Override
+        public long getExactSizeIfKnown() {
+            return get().getExactSizeIfKnown();
+        }
+
+        @Override
+        public String toString() {
+            return getClass().getName() + "[" + get() + "]";
+        }
+
+        static class OfInt extends DelegatingSpliterator<Integer> implements Spliterator.OfInt {
+
+            private Spliterator.OfInt s;
+
+            public OfInt(Supplier<Spliterator.OfInt> supplier) {
+                super(supplier);
+            }
+
+            @Override
+            Spliterator.OfInt get() {
+                if (s == null) {
+                    s = (Spliterator.OfInt) super.get();
+                }
+                return s;
+            }
+
+            @Override
+            public Spliterator.OfInt trySplit() {
+                return get().trySplit();
+            }
+
+            @Override
+            public boolean tryAdvance(IntConsumer consumer) {
+                return get().tryAdvance(consumer);
+            }
+
+            @Override
+            public void forEach(IntConsumer consumer) {
+                get().forEach(consumer);
+            }
+        }
+
+        static class OfLong extends DelegatingSpliterator<Long> implements Spliterator.OfLong {
+
+            Spliterator.OfLong s;
+
+            public OfLong(Supplier<Spliterator.OfLong> supplier) {
+                super(supplier);
+            }
+
+            @Override
+            Spliterator.OfLong get() {
+                if (s == null) {
+                    s = (Spliterator.OfLong) super.get();
+                }
+                return s;
+            }
+
+            @Override
+            public Spliterator.OfLong trySplit() {
+                return get().trySplit();
+            }
+
+            @Override
+            public boolean tryAdvance(LongConsumer consumer) {
+                return get().tryAdvance(consumer);
+            }
+
+            @Override
+            public void forEach(LongConsumer consumer) {
+                get().forEach(consumer);
+            }
+        }
+
+        static class OfDouble extends DelegatingSpliterator<Double> implements Spliterator.OfDouble {
+
+            Spliterator.OfDouble s;
+
+            public OfDouble(Supplier<Spliterator.OfDouble> supplier) {
+                super(supplier);
+            }
+
+            @Override
+            Spliterator.OfDouble get() {
+                if (s == null) {
+                    s = (Spliterator.OfDouble) super.get();
+                }
+                return s;
+            }
+
+            @Override
+            public Spliterator.OfDouble trySplit() {
+                return get().trySplit();
+            }
+
+            @Override
+            public boolean tryAdvance(DoubleConsumer consumer) {
+                return get().tryAdvance(consumer);
+            }
+
+            @Override
+            public void forEach(DoubleConsumer consumer) {
+                get().forEach(consumer);
+            }
+        }
+    }
+}
--- a/src/share/classes/java/util/stream/Streams.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/src/share/classes/java/util/stream/Streams.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,14 +24,10 @@
  */
 package java.util.stream;
 
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-import java.util.Objects;
-import java.util.Spliterator;
+import java.util.*;
+import java.util.Spliterators;
 import java.util.function.BiFunction;
 import java.util.function.Consumer;
-import java.util.function.DoubleConsumer;
 import java.util.function.DoubleSupplier;
 import java.util.function.DoubleUnaryOperator;
 import java.util.function.IntConsumer;
@@ -56,12 +52,10 @@
 
     public static final long MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
 
-    private static final int MAX_ITERATOR_CHUNK_SIZE = 1024;
-
     // Stream construction
 
     public static<T> Stream<T> emptyStream() {
-        return stream(emptySpliterator());
+        return stream(Spliterators.<T>emptySpliterator());
     }
 
     public static<T> Stream<T> stream(Supplier<? extends Spliterator<T>> source, int characteristics) {
@@ -87,7 +81,7 @@
     // IntStream construction
 
     public static IntStream emptyIntStream() {
-        return intStream(emptyIntSpliterator());
+        return intStream(Spliterators.emptyIntSpliterator());
     }
 
     public static IntStream intStream(Supplier<? extends Spliterator.OfInt> source, int characteristics) {
@@ -111,7 +105,7 @@
     // LongStream construction
 
     public static LongStream emptyLongStream() {
-        return longStream(emptyLongSpliterator());
+        return longStream(Spliterators.emptyLongSpliterator());
     }
 
     public static LongStream longStream(Supplier<? extends Spliterator.OfLong> source, int characteristics) {
@@ -135,7 +129,7 @@
     // DoubleStream construction
 
     public static DoubleStream emptyDoubleStream() {
-        return doubleStream(emptyDoubleSpliterator());
+        return doubleStream(Spliterators.emptyDoubleSpliterator());
     }
 
     public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> source, int characteristics) {
@@ -158,389 +152,10 @@
 
     // Empty iterators and spliterators
 
-    public static<T> Spliterator<T> emptySpliterator() {
-        return new EmptySpliterator<>();
-    }
-
-    public static <E> Spliterator.OfInt emptyIntSpliterator() {
-        return new EmptySpliterator.OfInt();
-    }
-
-    public static <E> Spliterator.OfLong emptyLongSpliterator() {
-        return new EmptySpliterator.OfLong();
-    }
-
-    public static <E> Spliterator.OfDouble emptyDoubleSpliterator() {
-        return new EmptySpliterator.OfDouble();
-    }
-
     // Iterators from spliterators
 
-    public static<T> Iterator<T> iteratorFrom(Spliterator<? extends T> spliterator) {
-        class Adapter implements Iterator<T>, Consumer<T> {
-            boolean valueReady = false;
-            T nextElement;
-
-            @Override
-            public void accept(T t) {
-                valueReady = true;
-                nextElement = t;
-            }
-
-            @Override
-            public boolean hasNext() {
-                Consumer<T> b = this;
-                if (!valueReady)
-                    spliterator.tryAdvance(b);
-                return valueReady;
-            }
-
-            @Override
-            public T next() {
-                if (!valueReady && !hasNext())
-                    throw new NoSuchElementException();
-                else {
-                    valueReady = false;
-                    return nextElement;
-                }
-            }
-        }
-
-        return new Adapter();
-    }
-
-    public static IntStream.IntIterator intIteratorFrom(Spliterator.OfInt spliterator) {
-        class Adapter implements IntStream.IntIterator, IntConsumer {
-            boolean valueReady = false;
-            int nextElement;
-
-            @Override
-            public void accept(int t) {
-                valueReady = true;
-                nextElement = t;
-            }
-
-            @Override
-            public boolean hasNext() {
-                if (!valueReady)
-                    spliterator.tryAdvance(this);
-                return valueReady;
-            }
-
-            @Override
-            public int nextInt() {
-                if (!valueReady && !hasNext())
-                    throw new NoSuchElementException();
-                else {
-                    valueReady = false;
-                    return nextElement;
-                }
-            }
-        }
-
-        return new Adapter();
-    }
-
-    public static LongStream.LongIterator longIteratorFrom(Spliterator.OfLong spliterator) {
-        class Adapter implements LongStream.LongIterator, LongConsumer {
-            boolean valueReady = false;
-            long nextElement;
-
-            @Override
-            public void accept(long t) {
-                valueReady = true;
-                nextElement = t;
-            }
-
-            @Override
-            public boolean hasNext() {
-                if (!valueReady)
-                    spliterator.tryAdvance(this);
-                return valueReady;
-            }
-
-            @Override
-            public long nextLong() {
-                if (!valueReady && !hasNext())
-                    throw new NoSuchElementException();
-                else {
-                    valueReady = false;
-                    return nextElement;
-                }
-            }
-        }
-
-        return new Adapter();
-    }
-
-    public static DoubleStream.DoubleIterator doubleIteratorFrom(Spliterator.OfDouble spliterator) {
-        class Adapter implements DoubleStream.DoubleIterator, DoubleConsumer {
-            boolean valueReady = false;
-            double nextElement;
-
-            @Override
-            public void accept(double t) {
-                valueReady = true;
-                nextElement = t;
-            }
-
-            @Override
-            public boolean hasNext() {
-                if (!valueReady)
-                    spliterator.tryAdvance(this);
-                return valueReady;
-            }
-
-            @Override
-            public double nextDouble() {
-                if (!valueReady && !hasNext())
-                    throw new NoSuchElementException();
-                else {
-                    valueReady = false;
-                    return nextElement;
-                }
-            }
-        }
-
-        return new Adapter();
-    }
-
     // Spliterators from iterators
 
-    public static<T> Spliterator<T> spliteratorUnknownSize(Iterator<T> iterator, int characteristics) {
-        return spliterator(iterator, -1, characteristics);
-    }
-
-    public static<T> Spliterator<T> spliterator(Iterator<T> iterator, long exactSizeIfKnown, int characteristics) {
-        Objects.requireNonNull(iterator);
-        return new Spliterator<T>() {
-            // The characteristics of this spliterator
-            final int c = exactSizeIfKnown >= 0
-                           ? characteristics | Spliterator.SIZED | Spliterator.SUBSIZED
-                           : characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
-            // The exact size of this spliterator, otherwise Long.MAX_VALUE
-            long size = exactSizeIfKnown >= 0 ? exactSizeIfKnown : Long.MAX_VALUE;
-            // The exact size of the spliterator returned from the next call to trySplit
-            int nextSize = 1;
-
-            @Override
-            public Spliterator<T> trySplit() {
-                if (!iterator.hasNext())
-                    return null;
-                else {
-                    @SuppressWarnings("unchecked")
-                    T[] array = (T[]) new Object[nextSize];
-                    int i = 0;
-                    while (i < array.length && iterator.hasNext())
-                        array[i++] = iterator.next();
-                    if (size < Long.MAX_VALUE) {
-                        size -= i;
-                    }
-                    nextSize = Math.min(nextSize * 2, MAX_ITERATOR_CHUNK_SIZE);
-                    // @@@ Need to inherit characteristics
-                    return Arrays.spliterator(array, 0, i);
-                }
-            }
-
-            @Override
-            public boolean tryAdvance(Consumer<? super T> consumer) {
-                boolean hasNext = iterator.hasNext();
-                if (hasNext)
-                    consumer.accept(iterator.next());
-                return hasNext;
-            }
-
-            @Override
-            public void forEach(Consumer<? super T> consumer) {
-                iterator.forEach(consumer);
-            }
-
-            @Override
-            public int characteristics() {
-                return c;
-            }
-
-            @Override
-            public long estimateSize() {
-                return size;
-            }
-        };
-    }
-
-    public static Spliterator.OfInt intSpliteratorUnknownSize(IntStream.IntIterator iterator, int characteristics) {
-        return intSpliterator(iterator, -1, characteristics);
-    }
-
-    public static Spliterator.OfInt intSpliterator(IntStream.IntIterator iterator, long exactSizeIfKnown, int characteristics) {
-        Objects.requireNonNull(iterator);
-        return new Spliterator.OfInt() {
-            // The characteristics of this spliterator
-            final int c = exactSizeIfKnown >= 0
-                          ? characteristics | Spliterator.SIZED | Spliterator.SUBSIZED
-                          : characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
-            // The exact size of this spliterator, otherwise Long.MAX_VALUE
-            long size = exactSizeIfKnown >= 0 ? exactSizeIfKnown : Long.MAX_VALUE;
-            // The exact size of the spliterator returned from the next call to trySplit
-            int nextSize = 1;
-
-            @Override
-            public Spliterator.OfInt trySplit() {
-                if (!iterator.hasNext())
-                    return null;
-                else {
-                    int[] array = new int[nextSize];
-                    int i = 0;
-                    while (i < array.length && iterator.hasNext())
-                        array[i++] = iterator.nextInt();
-                    if (size >= 0) {
-                        size -= i;
-                    }
-                    nextSize = Math.min(nextSize * 2, MAX_ITERATOR_CHUNK_SIZE);
-                    return Arrays.spliterator(array, 0, i);
-                }
-            }
-
-            @Override
-            public void forEach(IntConsumer consumer) {
-                iterator.forEachInt(consumer);
-            }
-
-            @Override
-            public boolean tryAdvance(IntConsumer consumer) {
-                boolean hasNext = iterator.hasNext();
-                if (hasNext)
-                    consumer.accept(iterator.nextInt());
-                return hasNext;
-            }
-
-            @Override
-            public int characteristics() {
-                return c;
-            }
-
-            @Override
-            public long estimateSize() {
-                return size;
-            }
-        };
-    }
-
-    public static Spliterator.OfLong longSpliteratorUnknownSize(LongStream.LongIterator iterator, int characteristics) {
-        return longSpliterator(iterator, -1, characteristics);
-    }
-
-    public static Spliterator.OfLong longSpliterator(LongStream.LongIterator iterator, long exactSizeIfKnown, int characteristics) {
-        Objects.requireNonNull(iterator);
-        return new Spliterator.OfLong() {
-            // The characteristics of this spliterator
-            final int c = exactSizeIfKnown >= 0
-                          ? characteristics | Spliterator.SIZED | Spliterator.SUBSIZED
-                          : characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
-            // The exact size of this spliterator, otherwise Long.MAX_VALUE
-            long size = exactSizeIfKnown >= 0 ? exactSizeIfKnown : Long.MAX_VALUE;
-            // The exact size of the spliterator returned from the next call to trySplit
-            int nextSize = 1;
-
-            @Override
-            public Spliterator.OfLong trySplit() {
-                if (!iterator.hasNext())
-                    return null;
-                else {
-                    long[] array = new long[nextSize];
-                    int i = 0;
-                    while (i < array.length && iterator.hasNext())
-                        array[i++] = iterator.nextLong();
-                    if (size >= 0) {
-                        size -= i;
-                    }
-                    nextSize = Math.min(nextSize * 2, MAX_ITERATOR_CHUNK_SIZE);
-                    return Arrays.spliterator(array, 0, i);
-                }
-            }
-
-            @Override
-            public void forEach(LongConsumer consumer) {
-                iterator.forEachLong(consumer);
-            }
-
-            @Override
-            public boolean tryAdvance(LongConsumer consumer) {
-                boolean hasNext = iterator.hasNext();
-                if (hasNext)
-                    consumer.accept(iterator.nextLong());
-                return hasNext;
-            }
-
-            @Override
-            public int characteristics() {
-                return c;
-            }
-
-            @Override
-            public long estimateSize() {
-                return size;
-            }
-        };
-    }
-
-    public static Spliterator.OfDouble doubleSpliteratorUnknownSize(DoubleStream.DoubleIterator iterator, int characteristics) {
-        return doubleSpliterator(iterator, -1, characteristics);
-    }
-
-    public static Spliterator.OfDouble doubleSpliterator(DoubleStream.DoubleIterator iterator, long exactSizeIfKnown, int characteristics) {
-        Objects.requireNonNull(iterator);
-        return new Spliterator.OfDouble() {
-            // The characteristics of this spliterator
-            final int c = exactSizeIfKnown >= 0
-                          ? characteristics | Spliterator.SIZED | Spliterator.SUBSIZED
-                          : characteristics & ~(Spliterator.SIZED | Spliterator.SUBSIZED);
-            // The exact size of this spliterator, otherwise Long.MAX_VALUE
-            long size = exactSizeIfKnown >= 0 ? exactSizeIfKnown : Long.MAX_VALUE;
-            // The exact size of the spliterator returned from the next call to trySplit
-            int nextSize = 1;
-
-            @Override
-            public Spliterator.OfDouble trySplit() {
-                if (!iterator.hasNext())
-                    return null;
-                else {
-                    double[] array = new double[nextSize];
-                    int i = 0;
-                    while (i < array.length && iterator.hasNext())
-                        array[i++] = iterator.nextDouble();
-                    if (size >= 0) {
-                        size -= i;
-                    }
-                    nextSize = Math.min(nextSize * 2, MAX_ITERATOR_CHUNK_SIZE);
-                    return Arrays.spliterator(array, 0, i);
-                }
-            }
-
-            @Override
-            public void forEach(DoubleConsumer consumer) {
-                iterator.forEachDouble(consumer);
-            }
-
-            @Override
-            public boolean tryAdvance(DoubleConsumer consumer) {
-                boolean hasNext = iterator.hasNext();
-                if (hasNext)
-                    consumer.accept(iterator.nextDouble());
-                return hasNext;
-            }
-
-            @Override
-            public int characteristics() {
-                return c;
-            }
-
-            @Override
-            public long estimateSize() {
-                return size;
-            }
-        };
-    }
-
     // Infinite stream generators
 
     public static<T> Stream<T> iterate(final T seed, final UnaryOperator<T> f) {
@@ -553,12 +168,12 @@
                 return t = (t == null) ? seed : f.apply(t);
             }
         };
-        return stream(spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     public static<T> Stream<T> generate(Supplier<T> f) {
         InfiniteIterator<T> iterator = f::get;
-        return stream(spliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     public static IntStream iterateInt(final int seed, final IntUnaryOperator f) {
@@ -573,12 +188,12 @@
                 return v;
             }
         };
-        return intStream(intSpliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return intStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     public static IntStream generateInt(IntSupplier f) {
         InfiniteIterator.OfInt iterator = f::getAsInt;
-        return intStream(intSpliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return intStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     /**
@@ -651,12 +266,12 @@
                 return v;
             }
         };
-        return longStream(longSpliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return longStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     public static LongStream generateLong(LongSupplier f) {
         InfiniteIterator.OfLong iterator = f::getAsLong;
-        return longStream(longSpliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return longStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     /**
@@ -730,12 +345,12 @@
                 return v;
             }
         };
-        return doubleStream(doubleSpliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return doubleStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     public static DoubleStream generateDouble(DoubleSupplier f) {
         InfiniteIterator.OfDouble iterator = f::getAsDouble;
-        return doubleStream(doubleSpliteratorUnknownSize(iterator, Spliterator.ORDERED));
+        return doubleStream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED));
     }
 
     // Concat
@@ -840,8 +455,8 @@
                      ? Math.min(aSpliterator.getExactSizeIfKnown(), bSpliterator.getExactSizeIfKnown())
                      : -1;
 
-        Iterator<A> aIterator = Streams.iteratorFrom(aSpliterator);
-        Iterator<B> bIterator = Streams.iteratorFrom(bSpliterator);
+        Iterator<A> aIterator = Spliterators.iteratorFromSpliterator(aSpliterator);
+        Iterator<B> bIterator = Spliterators.iteratorFromSpliterator(bSpliterator);
         Iterator<C> cIterator = new Iterator<C>() {
             @Override
             public boolean hasNext() {
@@ -854,7 +469,7 @@
             }
         };
 
-        Spliterator<C> split = spliterator(cIterator, zipSize, characteristics);
+        Spliterator<C> split = Spliterators.spliterator(cIterator, zipSize, characteristics);
         return (a.isParallel() || b.isParallel())
                ? parallelStream(split)
                : stream(split);
@@ -869,11 +484,11 @@
             return true;
         }
 
-        public interface OfInt extends InfiniteIterator<Integer>, IntStream.IntIterator { }
+        public interface OfInt extends InfiniteIterator<Integer>, PrimitiveIterator.OfInt { }
 
-        public interface OfLong extends InfiniteIterator<Long>, LongStream.LongIterator { }
+        public interface OfLong extends InfiniteIterator<Long>, PrimitiveIterator.OfLong { }
 
-        public interface OfDouble extends InfiniteIterator<Double>, DoubleStream.DoubleIterator { }
+        public interface OfDouble extends InfiniteIterator<Double>, PrimitiveIterator.OfDouble { }
     }
 
     private static class RangeIntSpliterator implements Spliterator.OfInt {
@@ -1006,77 +621,4 @@
         }
     }
 
-    private static class EmptySpliterator<T> implements Spliterator<T> {
-
-        @Override
-        public Spliterator<T> trySplit() {
-            return null;
-        }
-
-        @Override
-        public boolean tryAdvance(Consumer<? super T> consumer) {
-            return false;
-        }
-
-        @Override
-        public void forEach(Consumer<? super T> consumer) { }
-
-        @Override
-        public long estimateSize() {
-            return 0;
-        }
-
-        @Override
-        public int characteristics() {
-            return Spliterator.SIZED | Spliterator.SUBSIZED;
-        }
-
-        private static class OfInt extends EmptySpliterator<Integer> implements Spliterator.OfInt {
-            @Override
-            public Spliterator.OfInt trySplit() {
-                return null;
-            }
-
-            @Override
-            public boolean tryAdvance(IntConsumer consumer) {
-                return false;
-            }
-
-            @Override
-            public void forEach(IntConsumer consumer) {
-            }
-        }
-
-        private static class OfLong extends EmptySpliterator<Long> implements Spliterator.OfLong {
-            @Override
-            public Spliterator.OfLong trySplit() {
-                return null;
-            }
-
-            @Override
-            public boolean tryAdvance(LongConsumer consumer) {
-                return false;
-            }
-
-            @Override
-            public void forEach(LongConsumer consumer) {
-            }
-        }
-
-        private static class OfDouble extends EmptySpliterator<Double> implements Spliterator.OfDouble {
-            @Override
-            public Spliterator.OfDouble trySplit() {
-                return null;
-            }
-
-            @Override
-            public boolean tryAdvance(DoubleConsumer consumer) {
-                return false;
-            }
-
-            @Override
-            public void forEach(DoubleConsumer consumer) {
-            }
-        }
-    }
 }
--- a/test-ng/bootlib/java/util/stream/DoubleStreamTestData.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/DoubleStreamTestData.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.DoubleConsumer;
 import java.util.function.IntSupplier;
 import java.util.function.Supplier;
@@ -40,8 +42,8 @@
         return StreamShape.DOUBLE_VALUE;
     }
 
-    public DoubleStream.DoubleIterator iterator() {
-        return Streams.doubleIteratorFrom(spliterator());
+    public PrimitiveIterator.OfDouble iterator() {
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     @Override
--- a/test-ng/bootlib/java/util/stream/DoubleStreamTestDataProvider.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/DoubleStreamTestDataProvider.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,10 +26,8 @@
 
 import org.testng.annotations.DataProvider;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Spliterator;
+import java.util.*;
+import java.util.Spliterators;
 import java.util.function.Supplier;
 
 public class DoubleStreamTestDataProvider {
@@ -129,9 +127,9 @@
                                             () -> isl.spliterator()));
 
                 spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator(), size):" + name,
-                                            () -> Streams.doubleSpliterator(isl.iterator(), doubles.length, 0)));
+                                            () -> Spliterators.spliterator(isl.iterator(), doubles.length, 0)));
                 spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator()):" + name,
-                                            () -> Streams.doubleSpliteratorUnknownSize(isl.iterator(), 0)));
+                                            () -> Spliterators.spliteratorUnknownSize(isl.iterator(), 0)));
 
                 // @@@ Change to doubleRange when implemented
                 spliterators.add(splitDescr("Primitives.range(0,l):" + name,
--- a/test-ng/bootlib/java/util/stream/DoubleStreamTestScenario.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/DoubleStreamTestScenario.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,6 +24,7 @@
  */
 package java.util.stream;
 
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
 import java.util.function.Consumer;
 import java.util.function.DoubleConsumer;
@@ -52,7 +53,7 @@
 
     STREAM_ITERATOR(false) {
         <T, S_IN extends BaseStream<T, S_IN>> void _run(OpTestCase.TestData<T, S_IN> data, DoubleConsumer b, Function<S_IN, DoubleStream> m) {
-            for (DoubleStream.DoubleIterator seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
+            for (PrimitiveIterator.OfDouble seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
                 b.accept(seqIter.nextDouble());
         }
     },
--- a/test-ng/bootlib/java/util/stream/IntStreamTestData.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/IntStreamTestData.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.IntConsumer;
 import java.util.function.IntSupplier;
 import java.util.function.Supplier;
@@ -41,8 +43,8 @@
     }
 
     @Override
-    public IntStream.IntIterator iterator() {
-        return Streams.intIteratorFrom(spliterator());
+    public PrimitiveIterator.OfInt iterator() {
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     @Override
--- a/test-ng/bootlib/java/util/stream/IntStreamTestDataProvider.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/IntStreamTestDataProvider.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,10 +26,8 @@
 
 import org.testng.annotations.DataProvider;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Spliterator;
+import java.util.*;
+import java.util.Spliterators;
 import java.util.function.Supplier;
 
 public class IntStreamTestDataProvider {
@@ -137,9 +135,9 @@
                                             () -> isl.spliterator()));
 
                 spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator(), size):" + name,
-                                            () -> Streams.intSpliterator(isl.iterator(), ints.length, 0)));
+                                            () -> Spliterators.spliterator(isl.iterator(), ints.length, 0)));
                 spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator()):" + name,
-                                            () -> Streams.intSpliteratorUnknownSize(isl.iterator(), 0)));
+                                            () -> Spliterators.spliteratorUnknownSize(isl.iterator(), 0)));
 
                 spliterators.add(splitDescr("Streams.intRange(0,l):" + name,
                                             () -> Streams.intRange(0, ints.length).spliterator()));
--- a/test-ng/bootlib/java/util/stream/IntStreamTestScenario.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/IntStreamTestScenario.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,6 +24,7 @@
  */
 package java.util.stream;
 
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -52,7 +53,7 @@
 
     STREAM_ITERATOR(false) {
         <T, S_IN extends BaseStream<T, S_IN>> void _run(OpTestCase.TestData<T, S_IN> data, IntConsumer b, Function<S_IN, IntStream> m) {
-            for (IntStream.IntIterator seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
+            for (PrimitiveIterator.OfInt seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
                 b.accept(seqIter.nextInt());
         }
     },
--- a/test-ng/bootlib/java/util/stream/LambdaTestHelpers.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/LambdaTestHelpers.java	Fri Feb 22 18:53:32 2013 +0100
@@ -210,9 +210,9 @@
     }
 
     public static<T> void assertSorted(Iterator<T> i, Comparator<? super T> comp) {
-        if (i instanceof IntStream.IntIterator
-                || i instanceof DoubleStream.DoubleIterator
-                || i instanceof LongStream.LongIterator) {
+        if (i instanceof PrimitiveIterator.OfInt
+                || i instanceof PrimitiveIterator.OfDouble
+                || i instanceof PrimitiveIterator.OfLong) {
             i = toBoxedList(i).iterator();
         }
 
@@ -244,9 +244,9 @@
             return;
         }
 
-        if (iter instanceof IntStream.IntIterator
-            || iter instanceof DoubleStream.DoubleIterator
-            || iter instanceof LongStream.LongIterator) {
+        if (iter instanceof PrimitiveIterator.OfInt
+            || iter instanceof PrimitiveIterator.OfDouble
+            || iter instanceof PrimitiveIterator.OfLong) {
             iter = toBoxedList(iter).iterator();
         }
 
--- a/test-ng/bootlib/java/util/stream/LongStreamTestData.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/LongStreamTestData.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,7 +26,9 @@
 
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.IntSupplier;
 import java.util.function.LongConsumer;
 import java.util.function.Supplier;
@@ -40,8 +42,8 @@
         return StreamShape.LONG_VALUE;
     }
 
-    public LongStream.LongIterator iterator() {
-        return Streams.longIteratorFrom(spliterator());
+    public PrimitiveIterator.OfLong iterator() {
+        return Spliterators.iteratorFromSpliterator(spliterator());
     }
 
     @Override
--- a/test-ng/bootlib/java/util/stream/LongStreamTestDataProvider.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/LongStreamTestDataProvider.java	Fri Feb 22 18:53:32 2013 +0100
@@ -26,10 +26,8 @@
 
 import org.testng.annotations.DataProvider;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Spliterator;
+import java.util.*;
+import java.util.Spliterators;
 import java.util.function.Supplier;
 
 public class LongStreamTestDataProvider {
@@ -137,9 +135,9 @@
                                             () -> isl.spliterator()));
 
                 spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator(), size):" + name,
-                                            () -> Streams.longSpliterator(isl.iterator(), longs.length, 0)));
+                                            () -> Spliterators.spliterator(isl.iterator(), longs.length, 0)));
                 spliterators.add(splitDescr("Primitives.s(SpinedBuffer.iterator()):" + name,
-                                            () -> Streams.longSpliteratorUnknownSize(isl.iterator(), 0)));
+                                            () -> Spliterators.spliteratorUnknownSize(isl.iterator(), 0)));
 
                 spliterators.add(splitDescr("Streams.longRange(0,l):" + name,
                                             () -> Streams.longRange(0, longs.length).spliterator()));
--- a/test-ng/bootlib/java/util/stream/LongStreamTestScenario.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/LongStreamTestScenario.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,6 +24,7 @@
  */
 package java.util.stream;
 
+import java.util.PrimitiveIterator;
 import java.util.Spliterator;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -52,7 +53,7 @@
 
     STREAM_ITERATOR(false) {
         <T, S_IN extends BaseStream<T, S_IN>> void _run(OpTestCase.TestData<T, S_IN> data, LongConsumer b, Function<S_IN, LongStream> m) {
-            for (LongStream.LongIterator seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
+            for (PrimitiveIterator.OfLong seqIter = m.apply(data.stream()).iterator(); seqIter.hasNext(); )
                 b.accept(seqIter.nextLong());
         }
     },
--- a/test-ng/bootlib/java/util/stream/OpTestCase.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/OpTestCase.java	Fri Feb 22 18:53:32 2013 +0100
@@ -39,6 +39,7 @@
 import java.util.Objects;
 import java.util.Set;
 import java.util.Spliterator;
+import java.util.Spliterators;
 import java.util.function.BiConsumer;
 import java.util.function.Consumer;
 import java.util.function.Function;
@@ -147,9 +148,9 @@
 
         Collection<U> refResult;
 
-        Consumer<java.util.stream.OpTestCase.TestData<T, S_IN>> before = LambdaTestHelpers.bEmpty;
+        Consumer<OpTestCase.TestData<T, S_IN>> before = LambdaTestHelpers.bEmpty;
 
-        Consumer<java.util.stream.OpTestCase.TestData<T, S_IN>> after = LambdaTestHelpers.bEmpty;
+        Consumer<OpTestCase.TestData<T, S_IN>> after = LambdaTestHelpers.bEmpty;
 
         BiConsumer<Iterable<U>, Iterable<U>> sequentialEqualityAsserter = LambdaTestHelpers::assertContentsEqual;
         BiConsumer<Iterable<U>, Iterable<U>> parallelEqualityAsserter = LambdaTestHelpers::assertContentsEqual;
@@ -206,12 +207,12 @@
             return this;
         }
 
-        public ExerciseDataStreamBuilder<T, U, S_IN, S_OUT> before(Consumer<java.util.stream.OpTestCase.TestData<T, S_IN>> before) {
+        public ExerciseDataStreamBuilder<T, U, S_IN, S_OUT> before(Consumer<OpTestCase.TestData<T, S_IN>> before) {
             this.before = Objects.requireNonNull(before);
             return this;
         }
 
-        public ExerciseDataStreamBuilder<T, U, S_IN, S_OUT> after(Consumer<java.util.stream.OpTestCase.TestData<T, S_IN>> after) {
+        public ExerciseDataStreamBuilder<T, U, S_IN, S_OUT> after(Consumer<OpTestCase.TestData<T, S_IN>> after) {
             this.after = Objects.requireNonNull(after);
             return this;
         }
@@ -531,7 +532,7 @@
 
         @Override
         default Iterator<T> iterator() {
-            return Streams.iteratorFrom(spliterator());
+            return Spliterators.iteratorFromSpliterator(spliterator());
         }
 
         Spliterator<T> spliterator();
--- a/test-ng/bootlib/java/util/stream/StreamTestDataProvider.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/bootlib/java/util/stream/StreamTestDataProvider.java	Fri Feb 22 18:53:32 2013 +0100
@@ -27,7 +27,7 @@
 import org.testng.annotations.DataProvider;
 
 import java.util.*;
-import java.util.function.BiFunction;
+import java.util.Spliterators;
 import java.util.function.Supplier;
 
 /**
@@ -148,9 +148,9 @@
                 spliterators.add(splitDescr("SpinedBuffer.s():" + name,
                                             () -> new SpinedBuffer<>(Arrays.asList(ints)).spliterator()));
                 spliterators.add(splitDescr("Iterators.s(Arrays.s(array).iterator(), size):" + name,
-                                            () -> Streams.spliterator(Arrays.asList(ints).iterator(), ints.length, 0)));
+                                            () -> Spliterators.spliterator(Arrays.asList(ints).iterator(), ints.length, 0)));
                 spliterators.add(splitDescr("Iterators.s(Arrays.s(array).iterator()):" + name,
-                                            () -> Streams.spliteratorUnknownSize(Arrays.asList(ints).iterator(), 0)));
+                                            () -> Spliterators.spliteratorUnknownSize(Arrays.asList(ints).iterator(), 0)));
                 // @@@ Add map and collection spliterators when spliterator() is exposed on Collection or Iterable
             }
             spliteratorTestData = spliterators.toArray(new Object[0][]);
--- a/test-ng/boottests/java/util/stream/DoubleNodeTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/boottests/java/util/stream/DoubleNodeTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -27,6 +27,8 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.PrimitiveIterator;
+import java.util.Spliterators;
 import java.util.function.Function;
 
 import org.testng.annotations.DataProvider;
@@ -48,7 +50,7 @@
             List<Node<Double>> nodes = new ArrayList<>();
 
             nodes.add(Nodes.doubleNode(array));
-            nodes.add(degenerateTree(Streams.doubleIteratorFrom(Arrays.spliterator(array))));
+            nodes.add(degenerateTree(Spliterators.iteratorFromSpliterator(Arrays.spliterator(array))));
             nodes.add(tree(toList(array), l -> Nodes.doubleNode(toDoubleArray(l))));
             nodes.add(fill(array, Nodes.doubleMakeBuilder(array.length)));
             nodes.add(fill(array, Nodes.doubleMakeVariableSizeBuilder()));
@@ -95,7 +97,7 @@
         return nb.build();
     }
 
-    private Node.OfDouble degenerateTree(DoubleStream.DoubleIterator it) {
+    private Node.OfDouble degenerateTree(PrimitiveIterator.OfDouble it) {
         if (!it.hasNext()) {
             return Nodes.doubleNode(new double[0]);
         }
--- a/test-ng/boottests/java/util/stream/IntNodeTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/boottests/java/util/stream/IntNodeTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -27,6 +27,8 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.PrimitiveIterator;
+import java.util.Spliterators;
 import java.util.function.Function;
 
 import org.testng.annotations.DataProvider;
@@ -48,7 +50,7 @@
             List<Node<Integer>> nodes = new ArrayList<>();
 
             nodes.add(Nodes.intNode(array));
-            nodes.add(degenerateTree(Streams.intIteratorFrom(Arrays.spliterator(array))));
+            nodes.add(degenerateTree(Spliterators.iteratorFromSpliterator(Arrays.spliterator(array))));
             nodes.add(tree(toList(array), l -> Nodes.intNode(toIntArray(l))));
             nodes.add(fill(array, Nodes.intMakeBuilder(array.length)));
             nodes.add(fill(array, Nodes.intMakeVariableSizeBuilder()));
@@ -95,7 +97,7 @@
         return nb.build();
     }
 
-    private Node.OfInt degenerateTree(IntStream.IntIterator it) {
+    private Node.OfInt degenerateTree(PrimitiveIterator.OfInt it) {
         if (!it.hasNext()) {
             return Nodes.intNode(new int[0]);
         }
--- a/test-ng/boottests/java/util/stream/LongNodeTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/boottests/java/util/stream/LongNodeTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -27,6 +27,8 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.PrimitiveIterator;
+import java.util.Spliterators;
 import java.util.function.Function;
 
 import org.testng.annotations.DataProvider;
@@ -48,7 +50,7 @@
             List<Node<Long>> nodes = new ArrayList<>();
 
             nodes.add(Nodes.longNode(array));
-            nodes.add(degenerateTree(Streams.longIteratorFrom(Arrays.spliterator(array))));
+            nodes.add(degenerateTree(Spliterators.iteratorFromSpliterator(Arrays.spliterator(array))));
             nodes.add(tree(toList(array), l -> Nodes.longNode(toLongArray(l))));
             nodes.add(fill(array, Nodes.longMakeBuilder(array.length)));
             nodes.add(fill(array, Nodes.longMakeVariableSizeBuilder()));
@@ -95,7 +97,7 @@
         return nb.build();
     }
 
-    private Node.OfLong degenerateTree(LongStream.LongIterator it) {
+    private Node.OfLong degenerateTree(PrimitiveIterator.OfLong it) {
         if (!it.hasNext()) {
             return Nodes.longNode(new long[0]);
         }
--- a/test-ng/boottests/java/util/stream/SpinedBufferTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/boottests/java/util/stream/SpinedBufferTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -202,7 +202,7 @@
             list1.add(i);
             sb.accept(i);
         }
-        IntStream.IntIterator it = sb.iterator();
+        PrimitiveIterator.OfInt it = sb.iterator();
         for (int i = 0; i < 10000; i++)
             list2.add(it.nextInt());
         assertFalse(it.hasNext());
@@ -276,7 +276,7 @@
             list1.add(i);
             sb.accept(i);
         }
-        LongStream.LongIterator it = sb.iterator();
+        PrimitiveIterator.OfLong it = sb.iterator();
         for (int i = 0; i < 10000; i++)
             list2.add(it.nextLong());
         assertFalse(it.hasNext());
@@ -351,7 +351,7 @@
             list1.add((double) i);
             sb.accept((double) i);
         }
-        DoubleStream.DoubleIterator it = sb.iterator();
+        PrimitiveIterator.OfDouble it = sb.iterator();
         for (int i = 0; i < 10000; i++)
             list2.add(it.nextDouble());
         assertFalse(it.hasNext());
--- a/test-ng/tests/org/openjdk/tests/java/lang/CharSequenceStreamTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/lang/CharSequenceStreamTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -28,8 +28,8 @@
 import java.util.Arrays;
 import java.util.List;
 import java.util.NoSuchElementException;
+import java.util.PrimitiveIterator;
 import java.util.stream.Collectors;
-import java.util.stream.IntStream;
 
 import org.testng.annotations.Test;
 
@@ -40,7 +40,7 @@
 
     @Test(expectedExceptions = NoSuchElementException.class)
     public void testEmptyChars() {
-        IntStream.IntIterator s = "".chars().iterator();
+        PrimitiveIterator.OfInt s = "".chars().iterator();
         assertFalse(s.hasNext());
         int ch = s.nextInt();
     }
@@ -52,7 +52,7 @@
 
     @Test(expectedExceptions = NoSuchElementException.class)
     public void testEmptyCodePoints() {
-        IntStream.IntIterator s = "".codePoints().iterator();
+        PrimitiveIterator.OfInt s = "".codePoints().iterator();
         assertFalse(s.hasNext());
         int cp = s.nextInt();
     }
--- a/test-ng/tests/org/openjdk/tests/java/util/BitsetStreamTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/BitsetStreamTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -24,7 +24,7 @@
  */
 package org.openjdk.tests.java.util;
 
-import java.util.stream.IntStream;
+import java.util.PrimitiveIterator;
 import java.util.stream.StreamTestData;
 import java.util.stream.StreamTestDataProvider;
 import org.testng.annotations.Test;
@@ -58,7 +58,7 @@
         assertEquals(bs.cardinality(), data.stream().collect(Collectors.toSet()).size());
         assertEquals(bs.cardinality(), bs.stream().reduce(0, (s, i) -> s+1));
 
-        IntStream.IntIterator it = bs.stream().iterator();
+        PrimitiveIterator.OfInt it = bs.stream().iterator();
         for (int i=bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i+1)) {
             assertTrue(it.hasNext());
             assertEquals(it.nextInt(), i);
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/CollectionAndMapModifyStreamTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/CollectionAndMapModifyStreamTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -77,22 +77,18 @@
 
         collections.add(new ConcurrentSkipListSet<>(content));
 
+        ArrayBlockingQueue<Integer> arrayBlockingQueue = new ArrayBlockingQueue<>(content.size());
+        for (Integer i : content) arrayBlockingQueue.add(i);
+        collections.add(arrayBlockingQueue);
+        collections.add(new PriorityBlockingQueue<>(content));
         collections.add(new LinkedBlockingQueue<>(content));
         collections.add(new LinkedTransferQueue<>(content));
         collections.add(new ConcurrentLinkedQueue<>(content));
         collections.add(new LinkedBlockingDeque<>(content));
+        collections.add(new ConcurrentLinkedDeque<>(content));
 
-        // The following are not currently lazy
-//        ArrayBlockingQueue<Integer> arrayBlockingQueue = new ArrayBlockingQueue<>(content.size());
-//        for (Integer i : content) arrayBlockingQueue.add(i);
-//        collections.add(arrayBlockingQueue);
-
-//        collections.add(new PriorityBlockingQueue<>(content));
-
-//        collections.add(new ConcurrentLinkedDeque<>(content));
-
-//        collections.add(new CopyOnWriteArrayList<>(content));
-//        collections.add(new CopyOnWriteArraySet<>(content));
+        collections.add(new CopyOnWriteArrayList<>(content));
+        collections.add(new CopyOnWriteArraySet<>(content));
 
 
         Object[][] params = new Object[collections.size()][];
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/FindAnyOpTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/FindAnyOpTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -89,7 +89,7 @@
         OptionalInt or = withData(data).terminal(fs, s -> s.findAny()).equalator(INT_VALID_ANSWER).exercise();
         if (or.isPresent()) {
             int r = or.getAsInt();
-            IntStream.IntIterator it = fs.apply(data.stream()).iterator();
+            PrimitiveIterator.OfInt it = fs.apply(data.stream()).iterator();
             boolean contained = false;
             while (!contained && it.hasNext()) {
                 contained = r == it.nextInt();
@@ -113,7 +113,7 @@
         OptionalLong or = withData(data).terminal(fs, s -> s.findAny()).equalator(LONG_VALID_ANSWER).exercise();
         if (or.isPresent()) {
             long r = or.getAsLong();
-            LongStream.LongIterator it = fs.apply(data.stream()).iterator();
+            PrimitiveIterator.OfLong it = fs.apply(data.stream()).iterator();
             boolean contained = false;
             while (!contained && it.hasNext()) {
                 contained = r == it.nextLong();
@@ -137,7 +137,7 @@
         OptionalDouble or = withData(data).terminal(fs, s -> s.findAny()).equalator(DOUBLE_VALID_ANSWER).exercise();
         if (or.isPresent()) {
             double r = or.getAsDouble();
-            DoubleStream.DoubleIterator it = fs.apply(data.stream()).iterator();
+            PrimitiveIterator.OfDouble it = fs.apply(data.stream()).iterator();
             boolean contained = false;
             while (!contained && it.hasNext()) {
                 contained = r == it.nextDouble();
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/FindFirstOpTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/FindFirstOpTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -83,7 +83,7 @@
     void exerciseIntStream(IntStreamTestData data, Function<IntStream, IntStream> fs) {
         OptionalInt r = exerciseTerminalOps(data, fs, s -> s.findFirst());
         if (r.isPresent()) {
-            IntStream.IntIterator i = fs.apply(data.stream()).iterator();
+            PrimitiveIterator.OfInt i = fs.apply(data.stream()).iterator();
             assertTrue(i.hasNext());
             assertEquals(i.nextInt(), r.getAsInt());
         }
@@ -103,7 +103,7 @@
     void exerciseLongStream(LongStreamTestData data, Function<LongStream, LongStream> fs) {
         OptionalLong r = exerciseTerminalOps(data, fs, s -> s.findFirst());
         if (r.isPresent()) {
-            LongStream.LongIterator i = fs.apply(data.stream()).iterator();
+            PrimitiveIterator.OfLong i = fs.apply(data.stream()).iterator();
             assertTrue(i.hasNext());
             assertEquals(i.nextLong(), r.getAsLong());
         }
@@ -123,7 +123,7 @@
     void exerciseDoubleStream(DoubleStreamTestData data, Function<DoubleStream, DoubleStream> fs) {
         OptionalDouble r = exerciseTerminalOps(data, fs, s -> s.findFirst());
         if (r.isPresent()) {
-            DoubleStream.DoubleIterator i = fs.apply(data.stream()).iterator();
+            PrimitiveIterator.OfDouble i = fs.apply(data.stream()).iterator();
             assertTrue(i.hasNext());
             assertEquals(i.nextDouble(), r.getAsDouble());
         }
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/MatchOpTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/MatchOpTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -30,6 +30,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.PrimitiveIterator;
 import java.util.function.DoublePredicate;
 import java.util.function.DoubleSupplier;
 import java.util.function.Function;
@@ -204,10 +205,10 @@
 
     public void testIntInfinite() {
         class CycleSupplier implements IntSupplier {
-            final Supplier<IntStream.IntIterator> source;
-            IntStream.IntIterator i = null;
+            final Supplier<PrimitiveIterator.OfInt> source;
+            PrimitiveIterator.OfInt i = null;
 
-            CycleSupplier(Supplier<IntStream.IntIterator> source) {
+            CycleSupplier(Supplier<PrimitiveIterator.OfInt> source) {
                 this.source = source;
             }
 
@@ -220,7 +221,7 @@
             }
         }
 
-        Supplier<IntStream.IntIterator> source = () -> Arrays.stream(new int[]{1, 2, 3, 4}).iterator();
+        Supplier<PrimitiveIterator.OfInt> source = () -> Arrays.stream(new int[]{1, 2, 3, 4}).iterator();
 
         assertFalse(Streams.generateInt(new CycleSupplier(source)).allMatch(i -> i > 3));
         assertTrue(Streams.generateInt(new CycleSupplier(source)).anyMatch(i -> i > 3));
@@ -276,10 +277,10 @@
 
     public void testLongInfinite() {
         class CycleSupplier implements LongSupplier {
-            final Supplier<LongStream.LongIterator> source;
-            LongStream.LongIterator i = null;
+            final Supplier<PrimitiveIterator.OfLong> source;
+            PrimitiveIterator.OfLong i = null;
 
-            CycleSupplier(Supplier<LongStream.LongIterator> source) {
+            CycleSupplier(Supplier<PrimitiveIterator.OfLong> source) {
                 this.source = source;
             }
 
@@ -292,7 +293,7 @@
             }
         }
 
-        Supplier<LongStream.LongIterator> source = () -> Arrays.stream(new long[]{1, 2, 3, 4}).iterator();
+        Supplier<PrimitiveIterator.OfLong> source = () -> Arrays.stream(new long[]{1, 2, 3, 4}).iterator();
 
         assertFalse(Streams.generateLong(new CycleSupplier(source)).allMatch(i -> i > 3));
         assertTrue(Streams.generateLong(new CycleSupplier(source)).anyMatch(i -> i > 3));
@@ -348,10 +349,10 @@
 
     public void testDoubleInfinite() {
         class CycleSupplier implements DoubleSupplier {
-            final Supplier<DoubleStream.DoubleIterator> source;
-            DoubleStream.DoubleIterator i = null;
+            final Supplier<PrimitiveIterator.OfDouble> source;
+            PrimitiveIterator.OfDouble i = null;
 
-            CycleSupplier(Supplier<DoubleStream.DoubleIterator> source) {
+            CycleSupplier(Supplier<PrimitiveIterator.OfDouble> source) {
                 this.source = source;
             }
 
@@ -364,7 +365,7 @@
             }
         }
 
-        Supplier<DoubleStream.DoubleIterator> source = () -> Arrays.stream(new double[]{1, 2, 3, 4}).iterator();
+        Supplier<PrimitiveIterator.OfDouble> source = () -> Arrays.stream(new double[]{1, 2, 3, 4}).iterator();
 
         assertFalse(Streams.generateDouble(new CycleSupplier(source)).allMatch(i -> i > 3));
         assertTrue(Streams.generateDouble(new CycleSupplier(source)).anyMatch(i -> i > 3));
--- a/test-ng/tests/org/openjdk/tests/java/util/stream/SortedOpTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test-ng/tests/org/openjdk/tests/java/util/stream/SortedOpTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -27,6 +27,7 @@
 import org.testng.annotations.Test;
 
 import java.util.*;
+import java.util.Spliterators;
 import java.util.stream.*;
 
 import static java.util.stream.LambdaTestHelpers.*;
@@ -91,7 +92,7 @@
     }
 
     private <T> Stream<T> unknownSizeStream(List<T> l) {
-        return Streams.stream(Streams.spliteratorUnknownSize(l.iterator(), 0));
+        return Streams.stream(Spliterators.spliteratorUnknownSize(l.iterator(), 0));
     }
 
     @Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
@@ -157,7 +158,7 @@
     }
 
     private IntStream unknownSizeIntStream(int[] a) {
-        return Streams.intStream(Streams.intSpliteratorUnknownSize(Streams.intIteratorFrom(Arrays.spliterator(a)), 0));
+        return Streams.intStream(Spliterators.spliteratorUnknownSize(Spliterators.iteratorFromSpliterator(Arrays.spliterator(a)), 0));
     }
 
     @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
@@ -220,7 +221,7 @@
     }
 
     private LongStream unknownSizeLongStream(long[] a) {
-        return Streams.longStream(Streams.longSpliteratorUnknownSize(Streams.longIteratorFrom(Arrays.spliterator(a)), 0));
+        return Streams.longStream(Spliterators.spliteratorUnknownSize(Spliterators.iteratorFromSpliterator(Arrays.spliterator(a)), 0));
     }
 
     @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
@@ -283,7 +284,7 @@
     }
 
     private DoubleStream unknownSizeDoubleStream(double[] a) {
-        return Streams.doubleStream(Streams.doubleSpliteratorUnknownSize(Streams.doubleIteratorFrom(Arrays.spliterator(a)), 0));
+        return Streams.doubleStream(Spliterators.spliteratorUnknownSize(Spliterators.iteratorFromSpliterator(Arrays.spliterator(a)), 0));
     }
 
     @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
--- a/test/java/util/stream/Stream/IntegerStreamTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test/java/util/stream/Stream/IntegerStreamTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -38,7 +38,6 @@
 import java.util.function.Predicate;
 import java.util.function.Predicates;
 import java.util.stream.Collectors;
-import java.util.stream.IntStream;
 import java.util.stream.Stream;
 import java.util.stream.Streams;
 import static org.testng.Assert.*;
@@ -518,7 +517,7 @@
             Stream<Integer> stream2 = (type == ParallelType.Parallel) ? c.parallelStream():
                     (type == ParallelType.Sequential) ? c.stream().sequential() :
                     c.stream();
-            IntStream.IntIterator pit = stream2.map(LambdaUtilities.opToIntFunction(op, randOps)).iterator();
+            PrimitiveIterator.OfInt pit = stream2.map(LambdaUtilities.opToIntFunction(op, randOps)).iterator();
             verifyAfterOps(c.iterator(), pit, op, randOps);
         }
     }
@@ -1119,7 +1118,7 @@
 
     }
 
-    private void verifyAfterOps(Iterator<Integer> itOrg, IntStream.IntIterator pit, LambdaUtilities.IntOp op,
+    private void verifyAfterOps(Iterator<Integer> itOrg, PrimitiveIterator.OfInt pit, LambdaUtilities.IntOp op,
             int value) {
         while(itOrg.hasNext() && pit.hasNext()) {
             int expected = itOrg.next();
--- a/test/java/util/stream/Streams/BasicTest.java	Fri Feb 22 18:41:13 2013 +0100
+++ b/test/java/util/stream/Streams/BasicTest.java	Fri Feb 22 18:53:32 2013 +0100
@@ -32,7 +32,9 @@
 
 import java.util.Arrays;
 import java.util.Iterator;
+import java.util.PrimitiveIterator;
 import java.util.Random;
+import java.util.Spliterators;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.function.IntConsumer;
 import java.util.function.IntUnaryOperator;
@@ -64,7 +66,7 @@
 
         assertEquals(Streams.emptyPrimitiveSpliterator().estimateSize(), 0);
 
-        assertEquals(Streams.<String>emptySpliterator().estimateSize(), 0);
+        assertEquals(Spliterators.<String>emptySpliterator().estimateSize(), 0);
     }
 
     @Test
@@ -90,7 +92,7 @@
         IntUnaryOperator iuo = LambdaUtilities.opIntUnaryOperator(op, randomOpnd);
         IntStream isi = Streams.iterateInt(randomInit, iuo);
         int limitation = rand.nextInt( 1 << 10 );
-        IntStream.IntIterator pi = isi.limit(limitation).iterator();
+        PrimitiveIterator.OfInt pi = isi.limit(limitation).iterator();
 
         int next = randomInit;
 
@@ -108,13 +110,13 @@
             end = end ^ start;
             start = end ^ start;
         }
-        IntStream.IntIterator it1 = Streams.intRange(start, end).iterator();
+        PrimitiveIterator.OfInt it1 = Streams.intRange(start, end).iterator();
         while(it1.hasNext())
             assertEquals(it1.nextInt(), start++);
         assertEquals(start, end);
 
         int step = 2 << (rand.nextInt(31));
-        IntStream.IntIterator it2 = Streams.intRange(start, end, step).iterator();
+        PrimitiveIterator.OfInt it2 = Streams.intRange(start, end, step).iterator();
         while(it2.hasNext())
             assertEquals(it2.nextInt(), start += step);
         assertTrue(start + step > end);