From 52204a0bc4dd5e11206851543d15ac7594948e02 Mon Sep 17 00:00:00 2001 From: psandoz Date: Wed, 3 Jul 2013 21:43:49 +0200 Subject: [PATCH] 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method Reviewed-by: henryjen, briangoetz --- .../share/classes/java/io/BufferedReader.java | 2 +- .../share/classes/java/lang/CharSequence.java | 6 +- .../classes/java/nio/X-Buffer.java.template | 2 +- .../share/classes/java/nio/file/Files.java | 27 +- jdk/src/share/classes/java/util/Arrays.java | 8 +- jdk/src/share/classes/java/util/BitSet.java | 3 +- .../share/classes/java/util/Collection.java | 4 +- .../share/classes/java/util/Collections.java | 4 +- .../share/classes/java/util/jar/JarFile.java | 2 +- .../classes/java/util/regex/Pattern.java | 2 +- .../java/util/stream/DoubleStream.java | 12 +- .../classes/java/util/stream/IntStream.java | 16 +- .../classes/java/util/stream/LongStream.java | 16 +- .../classes/java/util/stream/Stream.java | 12 +- .../java/util/stream/StreamSupport.java | 388 +++++------------- .../classes/java/util/stream/Streams.java | 11 +- .../share/classes/java/util/zip/ZipFile.java | 2 +- .../util/stream/DoubleStreamTestScenario.java | 6 +- .../util/stream/IntStreamTestScenario.java | 7 +- .../util/stream/LongStreamTestScenario.java | 6 +- .../java/util/stream/StreamTestScenario.java | 6 +- .../bootlib/java/util/stream/TestData.java | 32 +- .../java/util/stream/DistinctOpTest.java | 4 +- .../stream/InfiniteStreamWithLimitOpTest.java | 2 +- .../tests/java/util/stream/MatchOpTest.java | 8 +- .../tests/java/util/stream/SliceOpTest.java | 2 +- .../tests/java/util/stream/SortedOpTest.java | 8 +- .../util/stream/StreamSpliteratorTest.java | 24 +- 28 files changed, 212 insertions(+), 410 deletions(-) diff --git a/jdk/src/share/classes/java/io/BufferedReader.java b/jdk/src/share/classes/java/io/BufferedReader.java index ebf398078b..98fe47c7a5 100644 --- a/jdk/src/share/classes/java/io/BufferedReader.java +++ b/jdk/src/share/classes/java/io/BufferedReader.java @@ -587,6 +587,6 @@ public class BufferedReader extends Reader { } } }; - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED)); + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED), false); } } diff --git a/jdk/src/share/classes/java/lang/CharSequence.java b/jdk/src/share/classes/java/lang/CharSequence.java index 3ee0b9ac1d..ac80b22f06 100644 --- a/jdk/src/share/classes/java/lang/CharSequence.java +++ b/jdk/src/share/classes/java/lang/CharSequence.java @@ -156,7 +156,8 @@ public interface CharSequence { new CharIterator(), length(), Spliterator.ORDERED), - Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED); + Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED, + false); } /** @@ -227,6 +228,7 @@ public interface CharSequence { Spliterators.spliteratorUnknownSize( new CodePointIterator(), Spliterator.ORDERED), - Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED); + Spliterator.SUBSIZED | Spliterator.SIZED | Spliterator.ORDERED, + false); } } diff --git a/jdk/src/share/classes/java/nio/X-Buffer.java.template b/jdk/src/share/classes/java/nio/X-Buffer.java.template index 03a7255c16..60f0733c9a 100644 --- a/jdk/src/share/classes/java/nio/X-Buffer.java.template +++ b/jdk/src/share/classes/java/nio/X-Buffer.java.template @@ -1495,7 +1495,7 @@ public abstract class $Type$Buffer #end[char] public $Streamtype$Stream $type$s() { return StreamSupport.$streamtype$Stream(() -> new $Type$BufferSpliterator(this), - Buffer.SPLITERATOR_CHARACTERISTICS); + Buffer.SPLITERATOR_CHARACTERISTICS, false); } #end[streamableType] diff --git a/jdk/src/share/classes/java/nio/file/Files.java b/jdk/src/share/classes/java/nio/file/Files.java index ca0263d066..586859f17d 100644 --- a/jdk/src/share/classes/java/nio/file/Files.java +++ b/jdk/src/share/classes/java/nio/file/Files.java @@ -3269,9 +3269,10 @@ public final class Files { } }; - return new DelegatingCloseableStream<>(ds, - StreamSupport.stream(Spliterators.spliteratorUnknownSize(it, - Spliterator.DISTINCT))); + Stream s = StreamSupport.stream( + Spliterators.spliteratorUnknownSize(it, Spliterator.DISTINCT), + false); + return new DelegatingCloseableStream<>(ds, s); } /** @@ -3358,9 +3359,12 @@ public final class Files { throws IOException { FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options); - return new DelegatingCloseableStream<>(iterator, - StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT)) - .map(entry -> entry.file())); + + Stream s = StreamSupport.stream( + Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), + false). + map(entry -> entry.file()); + return new DelegatingCloseableStream<>(iterator, s); } /** @@ -3455,10 +3459,13 @@ public final class Files { throws IOException { FileTreeIterator iterator = new FileTreeIterator(start, maxDepth, options); - return new DelegatingCloseableStream<>(iterator, - StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT)) - .filter(entry -> matcher.test(entry.file(), entry.attributes())) - .map(entry -> entry.file())); + + Stream s = StreamSupport.stream( + Spliterators.spliteratorUnknownSize(iterator, Spliterator.DISTINCT), + false). + filter(entry -> matcher.test(entry.file(), entry.attributes())). + map(entry -> entry.file()); + return new DelegatingCloseableStream<>(iterator, s); } /** diff --git a/jdk/src/share/classes/java/util/Arrays.java b/jdk/src/share/classes/java/util/Arrays.java index 196a31e576..3e81c11b8f 100644 --- a/jdk/src/share/classes/java/util/Arrays.java +++ b/jdk/src/share/classes/java/util/Arrays.java @@ -4966,7 +4966,7 @@ public class Arrays { * @since 1.8 */ public static Stream stream(T[] array, int startInclusive, int endExclusive) { - return StreamSupport.stream(spliterator(array, startInclusive, endExclusive)); + return StreamSupport.stream(spliterator(array, startInclusive, endExclusive), false); } /** @@ -4996,7 +4996,7 @@ public class Arrays { * @since 1.8 */ public static IntStream stream(int[] array, int startInclusive, int endExclusive) { - return StreamSupport.intStream(spliterator(array, startInclusive, endExclusive)); + return StreamSupport.intStream(spliterator(array, startInclusive, endExclusive), false); } /** @@ -5026,7 +5026,7 @@ public class Arrays { * @since 1.8 */ public static LongStream stream(long[] array, int startInclusive, int endExclusive) { - return StreamSupport.longStream(spliterator(array, startInclusive, endExclusive)); + return StreamSupport.longStream(spliterator(array, startInclusive, endExclusive), false); } /** @@ -5056,6 +5056,6 @@ public class Arrays { * @since 1.8 */ public static DoubleStream stream(double[] array, int startInclusive, int endExclusive) { - return StreamSupport.doubleStream(spliterator(array, startInclusive, endExclusive)); + return StreamSupport.doubleStream(spliterator(array, startInclusive, endExclusive), false); } } diff --git a/jdk/src/share/classes/java/util/BitSet.java b/jdk/src/share/classes/java/util/BitSet.java index 56faccc66f..35ecf70ea2 100644 --- a/jdk/src/share/classes/java/util/BitSet.java +++ b/jdk/src/share/classes/java/util/BitSet.java @@ -1231,6 +1231,7 @@ public class BitSet implements Cloneable, java.io.Serializable { new BitSetIterator(), cardinality(), Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED), Spliterator.SIZED | Spliterator.SUBSIZED | - Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED); + Spliterator.ORDERED | Spliterator.DISTINCT | Spliterator.SORTED, + false); } } diff --git a/jdk/src/share/classes/java/util/Collection.java b/jdk/src/share/classes/java/util/Collection.java index 249be10f0e..d42ba3e8a6 100644 --- a/jdk/src/share/classes/java/util/Collection.java +++ b/jdk/src/share/classes/java/util/Collection.java @@ -557,7 +557,7 @@ public interface Collection extends Iterable { * @since 1.8 */ default Stream stream() { - return StreamSupport.stream(spliterator()); + return StreamSupport.stream(spliterator(), false); } /** @@ -578,6 +578,6 @@ public interface Collection extends Iterable { * @since 1.8 */ default Stream parallelStream() { - return StreamSupport.parallelStream(spliterator()); + return StreamSupport.stream(spliterator(), true); } } diff --git a/jdk/src/share/classes/java/util/Collections.java b/jdk/src/share/classes/java/util/Collections.java index bbb987ec58..f56af07fd1 100644 --- a/jdk/src/share/classes/java/util/Collections.java +++ b/jdk/src/share/classes/java/util/Collections.java @@ -1674,12 +1674,12 @@ public class Collections { @Override public Stream> stream() { - return StreamSupport.stream(spliterator()); + return StreamSupport.stream(spliterator(), false); } @Override public Stream> parallelStream() { - return StreamSupport.parallelStream(spliterator()); + return StreamSupport.stream(spliterator(), true); } public Iterator> iterator() { diff --git a/jdk/src/share/classes/java/util/jar/JarFile.java b/jdk/src/share/classes/java/util/jar/JarFile.java index a70be7a6e2..f8deb7643a 100644 --- a/jdk/src/share/classes/java/util/jar/JarFile.java +++ b/jdk/src/share/classes/java/util/jar/JarFile.java @@ -272,7 +272,7 @@ class JarFile extends ZipFile { return StreamSupport.stream(Spliterators.spliterator( new JarEntryIterator(), size(), Spliterator.ORDERED | Spliterator.DISTINCT | - Spliterator.IMMUTABLE | Spliterator.NONNULL)); + Spliterator.IMMUTABLE | Spliterator.NONNULL), false); } private class JarFileEntry extends JarEntry { diff --git a/jdk/src/share/classes/java/util/regex/Pattern.java b/jdk/src/share/classes/java/util/regex/Pattern.java index 4d52151210..d7b800e325 100644 --- a/jdk/src/share/classes/java/util/regex/Pattern.java +++ b/jdk/src/share/classes/java/util/regex/Pattern.java @@ -5815,6 +5815,6 @@ NEXT: while (i <= last) { } } return StreamSupport.stream(Spliterators.spliteratorUnknownSize( - new MatcherIterator(), Spliterator.ORDERED | Spliterator.NONNULL)); + new MatcherIterator(), Spliterator.ORDERED | Spliterator.NONNULL), false); } } diff --git a/jdk/src/share/classes/java/util/stream/DoubleStream.java b/jdk/src/share/classes/java/util/stream/DoubleStream.java index 1b058abdf8..225de5e03b 100644 --- a/jdk/src/share/classes/java/util/stream/DoubleStream.java +++ b/jdk/src/share/classes/java/util/stream/DoubleStream.java @@ -672,7 +672,7 @@ public interface DoubleStream extends BaseStream { * @return an empty sequential stream */ public static DoubleStream empty() { - return StreamSupport.doubleStream(Spliterators.emptyDoubleSpliterator()); + return StreamSupport.doubleStream(Spliterators.emptyDoubleSpliterator(), false); } /** @@ -682,7 +682,7 @@ public interface DoubleStream extends BaseStream { * @return a singleton sequential stream */ public static DoubleStream of(double t) { - return StreamSupport.doubleStream(new Streams.DoubleStreamBuilderImpl(t)); + return StreamSupport.doubleStream(new Streams.DoubleStreamBuilderImpl(t), false); } /** @@ -730,7 +730,7 @@ public interface DoubleStream extends BaseStream { }; return StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize( iterator, - Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL)); + Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false); } /** @@ -744,7 +744,7 @@ public interface DoubleStream extends BaseStream { public static DoubleStream generate(DoubleSupplier s) { Objects.requireNonNull(s); return StreamSupport.doubleStream( - new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s)); + new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false); } /** @@ -764,8 +764,6 @@ public interface DoubleStream extends BaseStream { Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble( a.spliterator(), b.spliterator()); - return (a.isParallel() || b.isParallel()) - ? StreamSupport.doubleParallelStream(split) - : StreamSupport.doubleStream(split); + return StreamSupport.doubleStream(split, a.isParallel() || b.isParallel()); } } diff --git a/jdk/src/share/classes/java/util/stream/IntStream.java b/jdk/src/share/classes/java/util/stream/IntStream.java index 39e0713f1c..2ef55e15f9 100644 --- a/jdk/src/share/classes/java/util/stream/IntStream.java +++ b/jdk/src/share/classes/java/util/stream/IntStream.java @@ -674,7 +674,7 @@ public interface IntStream extends BaseStream { * @return an empty sequential stream */ public static IntStream empty() { - return StreamSupport.intStream(Spliterators.emptyIntSpliterator()); + return StreamSupport.intStream(Spliterators.emptyIntSpliterator(), false); } /** @@ -684,7 +684,7 @@ public interface IntStream extends BaseStream { * @return a singleton sequential stream */ public static IntStream of(int t) { - return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t)); + return StreamSupport.intStream(new Streams.IntStreamBuilderImpl(t), false); } /** @@ -732,7 +732,7 @@ public interface IntStream extends BaseStream { }; return StreamSupport.intStream(Spliterators.spliteratorUnknownSize( iterator, - Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL)); + Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false); } /** @@ -746,7 +746,7 @@ public interface IntStream extends BaseStream { public static IntStream generate(IntSupplier s) { Objects.requireNonNull(s); return StreamSupport.intStream( - new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s)); + new StreamSpliterators.InfiniteSupplyingSpliterator.OfInt(Long.MAX_VALUE, s), false); } /** @@ -771,7 +771,7 @@ public interface IntStream extends BaseStream { return empty(); } else { return StreamSupport.intStream( - new Streams.RangeIntSpliterator(startInclusive, endExclusive, false)); + new Streams.RangeIntSpliterator(startInclusive, endExclusive, false), false); } } @@ -797,7 +797,7 @@ public interface IntStream extends BaseStream { return empty(); } else { return StreamSupport.intStream( - new Streams.RangeIntSpliterator(startInclusive, endInclusive, true)); + new Streams.RangeIntSpliterator(startInclusive, endInclusive, true), false); } } @@ -818,8 +818,6 @@ public interface IntStream extends BaseStream { Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt( a.spliterator(), b.spliterator()); - return (a.isParallel() || b.isParallel()) - ? StreamSupport.intParallelStream(split) - : StreamSupport.intStream(split); + return StreamSupport.intStream(split, a.isParallel() || b.isParallel()); } } diff --git a/jdk/src/share/classes/java/util/stream/LongStream.java b/jdk/src/share/classes/java/util/stream/LongStream.java index 6e3bc68892..8d1c7eae8f 100644 --- a/jdk/src/share/classes/java/util/stream/LongStream.java +++ b/jdk/src/share/classes/java/util/stream/LongStream.java @@ -665,7 +665,7 @@ public interface LongStream extends BaseStream { * @return an empty sequential stream */ public static LongStream empty() { - return StreamSupport.longStream(Spliterators.emptyLongSpliterator()); + return StreamSupport.longStream(Spliterators.emptyLongSpliterator(), false); } /** @@ -675,7 +675,7 @@ public interface LongStream extends BaseStream { * @return a singleton sequential stream */ public static LongStream of(long t) { - return StreamSupport.longStream(new Streams.LongStreamBuilderImpl(t)); + return StreamSupport.longStream(new Streams.LongStreamBuilderImpl(t), false); } /** @@ -723,7 +723,7 @@ public interface LongStream extends BaseStream { }; return StreamSupport.longStream(Spliterators.spliteratorUnknownSize( iterator, - Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL)); + Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false); } /** @@ -737,7 +737,7 @@ public interface LongStream extends BaseStream { public static LongStream generate(LongSupplier s) { Objects.requireNonNull(s); return StreamSupport.longStream( - new StreamSpliterators.InfiniteSupplyingSpliterator.OfLong(Long.MAX_VALUE, s)); + new StreamSpliterators.InfiniteSupplyingSpliterator.OfLong(Long.MAX_VALUE, s), false); } /** @@ -769,7 +769,7 @@ public interface LongStream extends BaseStream { return concat(range(startInclusive, m), range(m, endExclusive)); } else { return StreamSupport.longStream( - new Streams.RangeLongSpliterator(startInclusive, endExclusive, false)); + new Streams.RangeLongSpliterator(startInclusive, endExclusive, false), false); } } @@ -803,7 +803,7 @@ public interface LongStream extends BaseStream { return concat(range(startInclusive, m), rangeClosed(m, endInclusive)); } else { return StreamSupport.longStream( - new Streams.RangeLongSpliterator(startInclusive, endInclusive, true)); + new Streams.RangeLongSpliterator(startInclusive, endInclusive, true), false); } } @@ -824,8 +824,6 @@ public interface LongStream extends BaseStream { Spliterator.OfLong split = new Streams.ConcatSpliterator.OfLong( a.spliterator(), b.spliterator()); - return (a.isParallel() || b.isParallel()) - ? StreamSupport.longParallelStream(split) - : StreamSupport.longStream(split); + return StreamSupport.longStream(split, a.isParallel() || b.isParallel()); } } diff --git a/jdk/src/share/classes/java/util/stream/Stream.java b/jdk/src/share/classes/java/util/stream/Stream.java index 78264e407e..ea166bdca3 100644 --- a/jdk/src/share/classes/java/util/stream/Stream.java +++ b/jdk/src/share/classes/java/util/stream/Stream.java @@ -805,7 +805,7 @@ public interface Stream extends BaseStream> { * @return an empty sequential stream */ public static Stream empty() { - return StreamSupport.stream(Spliterators.emptySpliterator()); + return StreamSupport.stream(Spliterators.emptySpliterator(), false); } /** @@ -816,7 +816,7 @@ public interface Stream extends BaseStream> { * @return a singleton sequential stream */ public static Stream of(T t) { - return StreamSupport.stream(new Streams.StreamBuilderImpl<>(t)); + return StreamSupport.stream(new Streams.StreamBuilderImpl<>(t), false); } /** @@ -866,7 +866,7 @@ public interface Stream extends BaseStream> { }; return StreamSupport.stream(Spliterators.spliteratorUnknownSize( iterator, - Spliterator.ORDERED | Spliterator.IMMUTABLE)); + Spliterator.ORDERED | Spliterator.IMMUTABLE), false); } /** @@ -881,7 +881,7 @@ public interface Stream extends BaseStream> { public static Stream generate(Supplier s) { Objects.requireNonNull(s); return StreamSupport.stream( - new StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<>(Long.MAX_VALUE, s)); + new StreamSpliterators.InfiniteSupplyingSpliterator.OfRef<>(Long.MAX_VALUE, s), false); } /** @@ -904,8 +904,6 @@ public interface Stream extends BaseStream> { @SuppressWarnings("unchecked") Spliterator split = new Streams.ConcatSpliterator.OfRef<>( (Spliterator) a.spliterator(), (Spliterator) b.spliterator()); - return (a.isParallel() || b.isParallel()) - ? StreamSupport.parallelStream(split) - : StreamSupport.stream(split); + return StreamSupport.stream(split, a.isParallel() || b.isParallel()); } } diff --git a/jdk/src/share/classes/java/util/stream/StreamSupport.java b/jdk/src/share/classes/java/util/stream/StreamSupport.java index 2b3cbfaeb7..0d9a5c36e8 100644 --- a/jdk/src/share/classes/java/util/stream/StreamSupport.java +++ b/jdk/src/share/classes/java/util/stream/StreamSupport.java @@ -47,32 +47,8 @@ public final class StreamSupport { private StreamSupport() {} /** - * Creates a new sequential {@code Stream} from a {@code Spliterator}. - * - *

The spliterator is only traversed, split, or queried for estimated - * size after the terminal operation of the stream pipeline commences. - * - *

It is strongly recommended the spliterator report a characteristic of - * {@code IMMUTABLE} or {@code CONCURRENT}, or be - * late-binding. Otherwise, - * {@link #stream(Supplier, int)} should be used to - * reduce the scope of potential interference with the source. See - * Non-Interference for - * more details. - * - * @param the type of stream elements - * @param spliterator a {@code Spliterator} describing the stream elements - * @return a new sequential {@code Stream} - */ - public static Stream stream(Spliterator spliterator) { - Objects.requireNonNull(spliterator); - return new ReferencePipeline.Head<>(spliterator, - StreamOpFlag.fromCharacteristics(spliterator), - false); - } - - /** - * Creates a new parallel {@code Stream} from a {@code Spliterator}. + * Creates a new sequential or parallel {@code Stream} from a + * {@code Spliterator}. * *

The spliterator is only traversed, split, or queried for estimated * size after the terminal operation of the stream pipeline commences. @@ -80,25 +56,28 @@ public final class StreamSupport { *

It is strongly recommended the spliterator report a characteristic of * {@code IMMUTABLE} or {@code CONCURRENT}, or be * late-binding. Otherwise, - * {@link #stream(Supplier, int)} should be used to - * reduce the scope of potential interference with the source. See + * {@link #stream(java.util.function.Supplier, int, boolean)} should be used + * to reduce the scope of potential interference with the source. See * Non-Interference for * more details. * * @param the type of stream elements * @param spliterator a {@code Spliterator} describing the stream elements - * @return a new parallel {@code Stream} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code Stream} */ - public static Stream parallelStream(Spliterator spliterator) { + public static Stream stream(Spliterator spliterator, boolean parallel) { Objects.requireNonNull(spliterator); return new ReferencePipeline.Head<>(spliterator, StreamOpFlag.fromCharacteristics(spliterator), - true); + parallel); } /** - * Creates a new sequential {@code Stream} from a {@code Supplier} of - * {@code Spliterator}. + * Creates a new sequential or parallel {@code Stream} from a + * {@code Supplier} of {@code Spliterator}. * *

The {@link Supplier#get()} method will be invoked on the supplier no * more than once, and after the terminal operation of the stream pipeline @@ -107,7 +86,8 @@ public final class StreamSupport { *

For spliterators that report a characteristic of {@code IMMUTABLE} * or {@code CONCURRENT}, or that are * late-binding, it is likely - * more efficient to use {@link #stream(java.util.Spliterator)} instead. + * more efficient to use {@link #stream(java.util.Spliterator, boolean)} + * instead. * The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation @@ -116,60 +96,28 @@ public final class StreamSupport { * Non-Interference for * more details. * - * @param the type of stream elements * @param supplier a {@code Supplier} of a {@code Spliterator} * @param characteristics Spliterator characteristics of the supplied * {@code Spliterator}. The characteristics must be equal to - * {@code source.get().getCharacteristics()}. - * @return a new sequential {@code Stream} - * @see #stream(Spliterator) + * {@code supplier.get().characteristics()}. + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code Stream} + * @see #stream(java.util.Spliterator, boolean) */ public static Stream stream(Supplier> supplier, - int characteristics) { + int characteristics, + boolean parallel) { Objects.requireNonNull(supplier); return new ReferencePipeline.Head<>(supplier, StreamOpFlag.fromCharacteristics(characteristics), - false); + parallel); } /** - * Creates a new parallel {@code Stream} from a {@code Supplier} of - * {@code Spliterator}. - * - *

The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline - * commences. - * - *

For spliterators that report a characteristic of {@code IMMUTABLE} - * or {@code CONCURRENT}, or that are - * late-binding, it is likely - * more efficient to use {@link #stream(Spliterator)} instead. - * The use of a {@code Supplier} in this form provides a level of - * indirection that reduces the scope of potential interference with the - * source. Since the supplier is only invoked after the terminal operation - * commences, any modifications to the source up to the start of the - * terminal operation are reflected in the stream result. See - * Non-Interference for - * more details. - * - * @param the type of stream elements - * @param supplier a {@code Supplier} of a {@code Spliterator} - * @param characteristics Spliterator characteristics of the supplied - * {@code Spliterator}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return a new parallel {@code Stream} - * @see #parallelStream(Spliterator) - */ - public static Stream parallelStream(Supplier> supplier, - int characteristics) { - Objects.requireNonNull(supplier); - return new ReferencePipeline.Head<>(supplier, - StreamOpFlag.fromCharacteristics(characteristics), - true); - } - - /** - * Creates a new sequential {@code IntStream} from a {@code Spliterator.OfInt}. + * Creates a new sequential or parallel {@code IntStream} from a + * {@code Spliterator.OfInt}. * *

The spliterator is only traversed, split, or queried for estimated size * after the terminal operation of the stream pipeline commences. @@ -177,46 +125,26 @@ public final class StreamSupport { *

It is strongly recommended the spliterator report a characteristic of * {@code IMMUTABLE} or {@code CONCURRENT}, or be * late-binding. Otherwise, - * {@link #stream(Supplier, int)}} should be used to - * reduce the scope of potential interference with the source. See + * {@link #intStream(java.util.function.Supplier, int, boolean)} should be + * used to reduce the scope of potential interference with the source. See * Non-Interference for * more details. * * @param spliterator a {@code Spliterator.OfInt} describing the stream elements - * @return a new sequential {@code IntStream} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code IntStream} */ - public static IntStream intStream(Spliterator.OfInt spliterator) { + public static IntStream intStream(Spliterator.OfInt spliterator, boolean parallel) { return new IntPipeline.Head<>(spliterator, StreamOpFlag.fromCharacteristics(spliterator), - false); + parallel); } /** - * Creates a new parallel {@code IntStream} from a {@code Spliterator.OfInt}. - * - *

he spliterator is only traversed, split, or queried for estimated size - * after the terminal operation of the stream pipeline commences. - * - *

It is strongly recommended the spliterator report a characteristic of - * {@code IMMUTABLE} or {@code CONCURRENT}, or be - * late-binding. Otherwise, - * {@link #stream(Supplier, int)}} should be used to - * reduce the scope of potential interference with the source. See - * Non-Interference for - * more details. - * - * @param spliterator a {@code Spliterator.OfInt} describing the stream elements - * @return a new parallel {@code IntStream} - */ - public static IntStream intParallelStream(Spliterator.OfInt spliterator) { - return new IntPipeline.Head<>(spliterator, - StreamOpFlag.fromCharacteristics(spliterator), - true); - } - - /** - * Creates a new sequential {@code IntStream} from a {@code Supplier} of - * {@code Spliterator.OfInt}. + * Creates a new sequential or parallel {@code IntStream} from a + * {@code Supplier} of {@code Spliterator.OfInt}. * *

The {@link Supplier#get()} method will be invoked on the supplier no * more than once, and after the terminal operation of the stream pipeline @@ -225,7 +153,8 @@ public final class StreamSupport { *

For spliterators that report a characteristic of {@code IMMUTABLE} * or {@code CONCURRENT}, or that are * late-binding, it is likely - * more efficient to use {@link #intStream(Spliterator.OfInt)} instead. + * more efficient to use {@link #intStream(java.util.Spliterator.OfInt, boolean)} + * instead. * The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation @@ -237,77 +166,24 @@ public final class StreamSupport { * @param supplier a {@code Supplier} of a {@code Spliterator.OfInt} * @param characteristics Spliterator characteristics of the supplied * {@code Spliterator.OfInt}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return a new sequential {@code IntStream} - * @see #intStream(Spliterator.OfInt) + * {@code supplier.get().characteristics()} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code IntStream} + * @see #intStream(java.util.Spliterator.OfInt, boolean) */ public static IntStream intStream(Supplier supplier, - int characteristics) { + int characteristics, + boolean parallel) { return new IntPipeline.Head<>(supplier, StreamOpFlag.fromCharacteristics(characteristics), - false); + parallel); } /** - * Creates a new parallel {@code IntStream} from a {@code Supplier} of - * {@code Spliterator.OfInt}. - * - *

The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline - * commences. - * - *

For spliterators that report a characteristic of {@code IMMUTABLE} - * or {@code CONCURRENT}, or that are - * late-binding, it is likely - * more efficient to use {@link #intStream(Spliterator.OfInt)} instead. - * The use of a {@code Supplier} in this form provides a level of - * indirection that reduces the scope of potential interference with the - * source. Since the supplier is only invoked after the terminal operation - * commences, any modifications to the source up to the start of the - * terminal operation are reflected in the stream result. See - * Non-Interference for - * more details. - * - * @param supplier a {@code Supplier} of a {@code Spliterator.OfInt} - * @param characteristics Spliterator characteristics of the supplied - * {@code Spliterator.OfInt}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return a new parallel {@code IntStream} - * @see #intParallelStream(Spliterator.OfInt) - */ - public static IntStream intParallelStream(Supplier supplier, - int characteristics) { - return new IntPipeline.Head<>(supplier, - StreamOpFlag.fromCharacteristics(characteristics), - true); - } - - /** - * Creates a new sequential {@code LongStream} from a {@code Spliterator.OfLong}. - * - *

The spliterator is only traversed, split, or queried for estimated - * size after the terminal operation of the stream pipeline commences. - * - *

It is strongly recommended the spliterator report a characteristic of - * {@code IMMUTABLE} or {@code CONCURRENT}, or be - * late-binding. Otherwise, - * {@link #stream(Supplier, int)} should be used to - * reduce the scope of potential interference with the source. See - * Non-Interference for - * more details. - * - * @param spliterator a {@code Spliterator.OfLong} describing the stream - * elements - * @return a new sequential {@code LongStream} - */ - public static LongStream longStream(Spliterator.OfLong spliterator) { - return new LongPipeline.Head<>(spliterator, - StreamOpFlag.fromCharacteristics(spliterator), - false); - } - - /** - * Creates a new parallel {@code LongStream} from a {@code Spliterator.OfLong}. + * Creates a new sequential or parallel {@code LongStream} from a + * {@code Spliterator.OfLong}. * *

The spliterator is only traversed, split, or queried for estimated * size after the terminal operation of the stream pipeline commences. @@ -315,23 +191,27 @@ public final class StreamSupport { *

It is strongly recommended the spliterator report a characteristic of * {@code IMMUTABLE} or {@code CONCURRENT}, or be * late-binding. Otherwise, - * {@link #stream(Supplier, int)} should be used to - * reduce the scope of potential interference with the source. See + * {@link #longStream(java.util.function.Supplier, int, boolean)} should be + * used to reduce the scope of potential interference with the source. See * Non-Interference for * more details. * * @param spliterator a {@code Spliterator.OfLong} describing the stream elements - * @return a new parallel {@code LongStream} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code LongStream} */ - public static LongStream longParallelStream(Spliterator.OfLong spliterator) { + public static LongStream longStream(Spliterator.OfLong spliterator, + boolean parallel) { return new LongPipeline.Head<>(spliterator, StreamOpFlag.fromCharacteristics(spliterator), - true); + parallel); } /** - * Creates a new sequential {@code LongStream} from a {@code Supplier} of - * {@code Spliterator.OfLong}. + * Creates a new sequential or parallel {@code LongStream} from a + * {@code Supplier} of {@code Spliterator.OfLong}. * *

The {@link Supplier#get()} method will be invoked on the supplier no * more than once, and after the terminal operation of the stream pipeline @@ -340,7 +220,8 @@ public final class StreamSupport { *

For spliterators that report a characteristic of {@code IMMUTABLE} * or {@code CONCURRENT}, or that are * late-binding, it is likely - * more efficient to use {@link #longStream(Spliterator.OfLong)} instead. + * more efficient to use {@link #longStream(java.util.Spliterator.OfLong, boolean)} + * instead. * The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation @@ -352,53 +233,23 @@ public final class StreamSupport { * @param supplier a {@code Supplier} of a {@code Spliterator.OfLong} * @param characteristics Spliterator characteristics of the supplied * {@code Spliterator.OfLong}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return a new sequential {@code LongStream} - * @see #longStream(Spliterator.OfLong) + * {@code supplier.get().characteristics()} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code LongStream} + * @see #longStream(java.util.Spliterator.OfLong, boolean) */ public static LongStream longStream(Supplier supplier, - int characteristics) { - return new LongPipeline.Head<>(supplier, - StreamOpFlag.fromCharacteristics(characteristics), - false); - } - - /** - * Creates a new parallel {@code LongStream} from a {@code Supplier} of - * {@code Spliterator.OfLong}. - * - *

The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline - * commences. - * - *

For spliterators that report a characteristic of {@code IMMUTABLE} - * or {@code CONCURRENT}, or that are - * late-binding, it is likely - * more efficient to use {@link #longStream(Spliterator.OfLong)} instead. - * The use of a {@code Supplier} in this form provides a level of - * indirection that reduces the scope of potential interference with the - * source. Since the supplier is only invoked after the terminal operation - * commences, any modifications to the source up to the start of the - * terminal operation are reflected in the stream result. See - * Non-Interference for - * more details. - * - * @param supplier A {@code Supplier} of a {@code Spliterator.OfLong} - * @param characteristics Spliterator characteristics of the supplied - * {@code Spliterator.OfLong}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return A new parallel {@code LongStream} - * @see #longParallelStream(Spliterator.OfLong) - */ - public static LongStream longParallelStream(Supplier supplier, - int characteristics) { + int characteristics, + boolean parallel) { return new LongPipeline.Head<>(supplier, StreamOpFlag.fromCharacteristics(characteristics), - true); + parallel); } /** - * Creates a new sequential {@code DoubleStream} from a + * Creates a new sequential or parallel {@code DoubleStream} from a * {@code Spliterator.OfDouble}. * *

The spliterator is only traversed, split, or queried for estimated size @@ -407,81 +258,27 @@ public final class StreamSupport { *

It is strongly recommended the spliterator report a characteristic of * {@code IMMUTABLE} or {@code CONCURRENT}, or be * late-binding. Otherwise, - * {@link #stream(Supplier, int)} should be used to - * reduce the scope of potential interference with the source. See + * {@link #doubleStream(java.util.function.Supplier, int, boolean)} should + * be used to reduce the scope of potential interference with the source. See * Non-Interference for * more details. * * @param spliterator A {@code Spliterator.OfDouble} describing the stream elements - * @return A new sequential {@code DoubleStream} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code DoubleStream} */ - public static DoubleStream doubleStream(Spliterator.OfDouble spliterator) { + public static DoubleStream doubleStream(Spliterator.OfDouble spliterator, + boolean parallel) { return new DoublePipeline.Head<>(spliterator, StreamOpFlag.fromCharacteristics(spliterator), - false); + parallel); } /** - * Creates a new parallel {@code DoubleStream} from a - * {@code Spliterator.OfDouble}. - * - *

The spliterator is only traversed, split, or queried for estimated size - * after the terminal operation of the stream pipeline commences. - * - *

It is strongly recommended the spliterator report a characteristic of - * {@code IMMUTABLE} or {@code CONCURRENT}, or be - * late-binding. Otherwise, - * {@link #stream(Supplier, int)} should be used to - * reduce the scope of potential interference with the source. See - * Non-Interference for - * more details. - * - * @param spliterator A {@code Spliterator.OfDouble} describing the stream elements - * @return A new parallel {@code DoubleStream} - */ - public static DoubleStream doubleParallelStream(Spliterator.OfDouble spliterator) { - return new DoublePipeline.Head<>(spliterator, - StreamOpFlag.fromCharacteristics(spliterator), - true); - } - - /** - * Creates a new sequential {@code DoubleStream} from a {@code Supplier} of - * {@code Spliterator.OfDouble}. - *

- * The {@link Supplier#get()} method will be invoked on the supplier no - * more than once, and after the terminal operation of the stream pipeline - * commences. - *

- * For spliterators that report a characteristic of {@code IMMUTABLE} - * or {@code CONCURRENT}, or that are - * late-binding, it is likely - * more efficient to use {@link #doubleStream(Spliterator.OfDouble)} instead. - * The use of a {@code Supplier} in this form provides a level of - * indirection that reduces the scope of potential interference with the - * source. Since the supplier is only invoked after the terminal operation - * commences, any modifications to the source up to the start of the - * terminal operation are reflected in the stream result. See - * Non-Interference for - * more details. - * - * @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble} - * @param characteristics Spliterator characteristics of the supplied - * {@code Spliterator.OfDouble}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return A new sequential {@code DoubleStream} - * @see #doubleStream(Spliterator.OfDouble) - */ - public static DoubleStream doubleStream(Supplier supplier, - int characteristics) { - return new DoublePipeline.Head<>(supplier, - StreamOpFlag.fromCharacteristics(characteristics), - false); - } - - /** - * Creates a new parallel {@code DoubleStream} from a {@code Supplier} of - * {@code Spliterator.OfDouble}. + * Creates a new sequential or parallel {@code DoubleStream} from a + * {@code Supplier} of {@code Spliterator.OfDouble}. * *

The {@link Supplier#get()} method will be invoked on the supplier no * more than once, and after the terminal operation of the stream pipeline @@ -490,7 +287,8 @@ public final class StreamSupport { *

For spliterators that report a characteristic of {@code IMMUTABLE} * or {@code CONCURRENT}, or that are * late-binding, it is likely - * more efficient to use {@link #doubleStream(Spliterator.OfDouble)} instead. + * more efficient to use {@link #doubleStream(java.util.Spliterator.OfDouble, boolean)} + * instead. * The use of a {@code Supplier} in this form provides a level of * indirection that reduces the scope of potential interference with the * source. Since the supplier is only invoked after the terminal operation @@ -499,17 +297,21 @@ public final class StreamSupport { * Non-Interference for * more details. * - * @param supplier a {@code Supplier} of a {@code Spliterator.OfDouble} + * @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble} * @param characteristics Spliterator characteristics of the supplied * {@code Spliterator.OfDouble}. The characteristics must be equal to - * {@code source.get().getCharacteristics()} - * @return a new parallel {@code DoubleStream} - * @see #doubleParallelStream(Spliterator.OfDouble) + * {@code supplier.get().characteristics()} + * @param parallel if {@code true} then the returned stream is a parallel + * stream; if {@code false} the returned stream is a sequential + * stream. + * @return a new sequential or parallel {@code DoubleStream} + * @see #doubleStream(java.util.Spliterator.OfDouble, boolean) */ - public static DoubleStream doubleParallelStream(Supplier supplier, - int characteristics) { + public static DoubleStream doubleStream(Supplier supplier, + int characteristics, + boolean parallel) { return new DoublePipeline.Head<>(supplier, StreamOpFlag.fromCharacteristics(characteristics), - true); + parallel); } } diff --git a/jdk/src/share/classes/java/util/stream/Streams.java b/jdk/src/share/classes/java/util/stream/Streams.java index 1d49997fe2..21fe270628 100644 --- a/jdk/src/share/classes/java/util/stream/Streams.java +++ b/jdk/src/share/classes/java/util/stream/Streams.java @@ -25,10 +25,7 @@ package java.util.stream; import java.util.Comparator; -import java.util.Objects; import java.util.Spliterator; -import java.util.Spliterators; -import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.DoubleConsumer; import java.util.function.IntConsumer; @@ -379,7 +376,7 @@ final class Streams { count = -count - 1; // Use this spliterator if 0 or 1 elements, otherwise use // the spliterator of the spined buffer - return (c < 2) ? StreamSupport.stream(this) : StreamSupport.stream(buffer.spliterator()); + return (c < 2) ? StreamSupport.stream(this, false) : StreamSupport.stream(buffer.spliterator(), false); } throw new IllegalStateException(); @@ -466,7 +463,7 @@ final class Streams { count = -count - 1; // Use this spliterator if 0 or 1 elements, otherwise use // the spliterator of the spined buffer - return (c < 2) ? StreamSupport.intStream(this) : StreamSupport.intStream(buffer.spliterator()); + return (c < 2) ? StreamSupport.intStream(this, false) : StreamSupport.intStream(buffer.spliterator(), false); } throw new IllegalStateException(); @@ -553,7 +550,7 @@ final class Streams { count = -count - 1; // Use this spliterator if 0 or 1 elements, otherwise use // the spliterator of the spined buffer - return (c < 2) ? StreamSupport.longStream(this) : StreamSupport.longStream(buffer.spliterator()); + return (c < 2) ? StreamSupport.longStream(this, false) : StreamSupport.longStream(buffer.spliterator(), false); } throw new IllegalStateException(); @@ -640,7 +637,7 @@ final class Streams { count = -count - 1; // Use this spliterator if 0 or 1 elements, otherwise use // the spliterator of the spined buffer - return (c < 2) ? StreamSupport.doubleStream(this) : StreamSupport.doubleStream(buffer.spliterator()); + return (c < 2) ? StreamSupport.doubleStream(this, false) : StreamSupport.doubleStream(buffer.spliterator(), false); } throw new IllegalStateException(); diff --git a/jdk/src/share/classes/java/util/zip/ZipFile.java b/jdk/src/share/classes/java/util/zip/ZipFile.java index 97d415c4a5..6a023f8135 100644 --- a/jdk/src/share/classes/java/util/zip/ZipFile.java +++ b/jdk/src/share/classes/java/util/zip/ZipFile.java @@ -551,7 +551,7 @@ class ZipFile implements ZipConstants, Closeable { return StreamSupport.stream(Spliterators.spliterator( new ZipEntryIterator(), size(), Spliterator.ORDERED | Spliterator.DISTINCT | - Spliterator.IMMUTABLE | Spliterator.NONNULL)); + Spliterator.IMMUTABLE | Spliterator.NONNULL), false); } private ZipEntry getZipEntry(String name, long jzentry) { diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java index 5e431b1325..d4459cf0c9 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/DoubleStreamTestScenario.java @@ -140,9 +140,9 @@ public enum DoubleStreamTestScenario implements OpTestCase.BaseStreamTestScenari void _run(TestData data, DoubleConsumer b, Function m) { DoubleStream s = m.apply(data.parallelStream()); Spliterator.OfDouble sp = s.spliterator(); - DoubleStream ss = StreamSupport.doubleParallelStream(() -> sp, - StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) - | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED)); + DoubleStream ss = StreamSupport.doubleStream(() -> sp, + StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) + | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED), true); for (double t : ss.toArray()) b.accept(t); } diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java index c12a4ec1ec..f399cdeef2 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/IntStreamTestScenario.java @@ -140,9 +140,10 @@ public enum IntStreamTestScenario implements OpTestCase.BaseStreamTestScenario { void _run(TestData data, IntConsumer b, Function m) { IntStream s = m.apply(data.parallelStream()); Spliterator.OfInt sp = s.spliterator(); - IntStream ss = StreamSupport.intParallelStream(() -> sp, - StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) - | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED)); + IntStream ss = StreamSupport.intStream(() -> sp, + StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) + | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED), + true); for (int t : ss.toArray()) b.accept(t); } diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java index c32d6e8242..3010745a55 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/LongStreamTestScenario.java @@ -140,9 +140,9 @@ public enum LongStreamTestScenario implements OpTestCase.BaseStreamTestScenario void _run(TestData data, LongConsumer b, Function m) { LongStream s = m.apply(data.parallelStream()); Spliterator.OfLong sp = s.spliterator(); - LongStream ss = StreamSupport.longParallelStream(() -> sp, - StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) - | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED)); + LongStream ss = StreamSupport.longStream(() -> sp, + StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) + | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED), true); for (long t : ss.toArray()) b.accept(t); } diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java b/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java index c7f09eab1d..b1abd4320d 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/StreamTestScenario.java @@ -151,9 +151,9 @@ public enum StreamTestScenario implements OpTestCase.BaseStreamTestScenario { void _run(TestData data, Consumer b, Function> m) { Stream s = m.apply(data.parallelStream()); Spliterator sp = s.spliterator(); - Stream ss = StreamSupport.parallelStream(() -> sp, - StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) - | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED)); + Stream ss = StreamSupport.stream(() -> sp, + StreamOpFlag.toCharacteristics(OpTestCase.getStreamFlags(s)) + | (sp.getExactSizeIfKnown() < 0 ? 0 : Spliterator.SIZED), true); for (Object t : ss.toArray()) b.accept((U) t); } diff --git a/jdk/test/java/util/stream/bootlib/java/util/stream/TestData.java b/jdk/test/java/util/stream/bootlib/java/util/stream/TestData.java index c204b318ed..f4f0392e5c 100644 --- a/jdk/test/java/util/stream/bootlib/java/util/stream/TestData.java +++ b/jdk/test/java/util/stream/bootlib/java/util/stream/TestData.java @@ -87,8 +87,8 @@ public interface TestData> public static OfRef ofSpinedBuffer(String name, SpinedBuffer buffer) { return new AbstractTestData.RefTestData<>(name, buffer, - b -> StreamSupport.stream(b.spliterator()), - b -> StreamSupport.parallelStream(b.spliterator()), + b -> StreamSupport.stream(b.spliterator(), false), + b -> StreamSupport.stream(b.spliterator(), true), SpinedBuffer::spliterator, b -> (int) b.count()); } @@ -103,8 +103,8 @@ public interface TestData> public static OfRef ofRefNode(String name, Node node) { return new AbstractTestData.RefTestData<>(name, node, - n -> StreamSupport.stream(n::spliterator, Spliterator.SIZED | Spliterator.ORDERED), - n -> StreamSupport.parallelStream(n::spliterator, Spliterator.SIZED | Spliterator.ORDERED), + n -> StreamSupport.stream(n::spliterator, Spliterator.SIZED | Spliterator.ORDERED, false), + n -> StreamSupport.stream(n::spliterator, Spliterator.SIZED | Spliterator.ORDERED, true), Node::spliterator, n -> (int) n.count()); } @@ -117,8 +117,8 @@ public interface TestData> public static OfInt ofSpinedBuffer(String name, SpinedBuffer.OfInt buffer) { return new AbstractTestData.IntTestData<>(name, buffer, - b -> StreamSupport.intStream(b.spliterator()), - b -> StreamSupport.intParallelStream(b.spliterator()), + b -> StreamSupport.intStream(b.spliterator(), false), + b -> StreamSupport.intStream(b.spliterator(), true), SpinedBuffer.OfInt::spliterator, b -> (int) b.count()); } @@ -134,8 +134,8 @@ public interface TestData> public static OfInt ofNode(String name, Node.OfInt node) { int characteristics = Spliterator.SIZED | Spliterator.ORDERED; return new AbstractTestData.IntTestData<>(name, node, - n -> StreamSupport.intStream(n::spliterator, characteristics), - n -> StreamSupport.intParallelStream(n::spliterator, characteristics), + n -> StreamSupport.intStream(n::spliterator, characteristics, false), + n -> StreamSupport.intStream(n::spliterator, characteristics, true), Node.OfInt::spliterator, n -> (int) n.count()); } @@ -148,8 +148,8 @@ public interface TestData> public static OfLong ofSpinedBuffer(String name, SpinedBuffer.OfLong buffer) { return new AbstractTestData.LongTestData<>(name, buffer, - b -> StreamSupport.longStream(b.spliterator()), - b -> StreamSupport.longParallelStream(b.spliterator()), + b -> StreamSupport.longStream(b.spliterator(), false), + b -> StreamSupport.longStream(b.spliterator(), true), SpinedBuffer.OfLong::spliterator, b -> (int) b.count()); } @@ -165,8 +165,8 @@ public interface TestData> public static OfLong ofNode(String name, Node.OfLong node) { int characteristics = Spliterator.SIZED | Spliterator.ORDERED; return new AbstractTestData.LongTestData<>(name, node, - n -> StreamSupport.longStream(n::spliterator, characteristics), - n -> StreamSupport.longParallelStream(n::spliterator, characteristics), + n -> StreamSupport.longStream(n::spliterator, characteristics, false), + n -> StreamSupport.longStream(n::spliterator, characteristics, true), Node.OfLong::spliterator, n -> (int) n.count()); } @@ -179,8 +179,8 @@ public interface TestData> public static OfDouble ofSpinedBuffer(String name, SpinedBuffer.OfDouble buffer) { return new AbstractTestData.DoubleTestData<>(name, buffer, - b -> StreamSupport.doubleStream(b.spliterator()), - b -> StreamSupport.doubleParallelStream(b.spliterator()), + b -> StreamSupport.doubleStream(b.spliterator(), false), + b -> StreamSupport.doubleStream(b.spliterator(), true), SpinedBuffer.OfDouble::spliterator, b -> (int) b.count()); } @@ -196,8 +196,8 @@ public interface TestData> public static OfDouble ofNode(String name, Node.OfDouble node) { int characteristics = Spliterator.SIZED | Spliterator.ORDERED; return new AbstractTestData.DoubleTestData<>(name, node, - n -> StreamSupport.doubleStream(n::spliterator, characteristics), - n -> StreamSupport.doubleParallelStream(n::spliterator, characteristics), + n -> StreamSupport.doubleStream(n::spliterator, characteristics, false), + n -> StreamSupport.doubleStream(n::spliterator, characteristics, true), Node.OfDouble::spliterator, n -> (int) n.count()); } diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java index ddadacc5a1..8d9e3f8c01 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/DistinctOpTest.java @@ -86,8 +86,8 @@ public class DistinctOpTest extends OpTestCase { static class SortedTestData extends TestData.AbstractTestData.RefTestData> { SortedTestData(List coll) { super("SortedTestData", coll, - c -> StreamSupport.stream(Spliterators.spliterator(c.toArray(), Spliterator.ORDERED | Spliterator.SORTED)), - c -> StreamSupport.parallelStream(Spliterators.spliterator(c.toArray(), Spliterator.ORDERED | Spliterator.SORTED)), + c -> StreamSupport.stream(Spliterators.spliterator(c.toArray(), Spliterator.ORDERED | Spliterator.SORTED), false), + c -> StreamSupport.stream(Spliterators.spliterator(c.toArray(), Spliterator.ORDERED | Spliterator.SORTED), true), c -> Spliterators.spliterator(c.toArray(), Spliterator.ORDERED | Spliterator.SORTED), List::size); } diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java index dc086668f5..0915839415 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/InfiniteStreamWithLimitOpTest.java @@ -306,7 +306,7 @@ public class InfiniteStreamWithLimitOpTest extends OpTestCase { private TestData.OfLong proxiedLongRange(long l, long u) { return TestData.Factory.ofLongSupplier( String.format("[%d, %d)", l, u), - () -> StreamSupport.longStream(proxyNotSubsized(LongStream.range(l, u).spliterator()))); + () -> StreamSupport.longStream(proxyNotSubsized(LongStream.range(l, u).spliterator()), false)); } @Test(dataProvider = "Stream.limit") diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/MatchOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/MatchOpTest.java index e88a8d95e9..dc825da558 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/MatchOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/MatchOpTest.java @@ -155,7 +155,7 @@ public class MatchOpTest extends OpTestCase { } Supplier> source = () -> Arrays.asList(1, 2, 3, 4).iterator(); - Supplier> s = () -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0)); + Supplier> s = () -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0), false); assertFalse(s.get().allMatch(i -> i > 3)); assertTrue(s.get().anyMatch(i -> i > 3)); @@ -240,7 +240,7 @@ public class MatchOpTest extends OpTestCase { } Supplier source = () -> Arrays.stream(new int[]{1, 2, 3, 4}).iterator(); - Supplier s = () -> StreamSupport.intStream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0)); + Supplier s = () -> StreamSupport.intStream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0), false); assertFalse(s.get().allMatch(i -> i > 3)); assertTrue(s.get().anyMatch(i -> i > 3)); @@ -325,7 +325,7 @@ public class MatchOpTest extends OpTestCase { } Supplier source = () -> Arrays.stream(new long[]{1, 2, 3, 4}).iterator(); - Supplier s = () -> StreamSupport.longStream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0)); + Supplier s = () -> StreamSupport.longStream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0), false); assertFalse(s.get().allMatch(i -> i > 3)); assertTrue(s.get().anyMatch(i -> i > 3)); @@ -410,7 +410,7 @@ public class MatchOpTest extends OpTestCase { } Supplier source = () -> Arrays.stream(new double[]{1, 2, 3, 4}).iterator(); - Supplier s = () -> StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0)); + Supplier s = () -> StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(new CycleIterator(source), 0), false); assertFalse(s.get().allMatch(i -> i > 3)); assertTrue(s.get().anyMatch(i -> i > 3)); diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SliceOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SliceOpTest.java index afa1b01265..b8c9b54a34 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SliceOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SliceOpTest.java @@ -237,7 +237,7 @@ public class SliceOpTest extends OpTestCase { List list = IntStream.range(0, 100).boxed().collect(Collectors.toList()); TestData.OfRef data = TestData.Factory.ofSupplier( "Non splitting, not SUBSIZED, ORDERED, stream", - () -> StreamSupport.stream(new NonSplittingNotSubsizedOrderedSpliterator<>(list.spliterator()))); + () -> StreamSupport.stream(new NonSplittingNotSubsizedOrderedSpliterator<>(list.spliterator()), false)); testSkipLimitOps("testSkipLimitOpsWithNonSplittingSpliterator", data); } diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SortedOpTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SortedOpTest.java index 956dea39ec..6c8cab2182 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SortedOpTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/SortedOpTest.java @@ -78,7 +78,7 @@ public class SortedOpTest extends OpTestCase { } private Stream unknownSizeStream(List l) { - return StreamSupport.stream(Spliterators.spliteratorUnknownSize(l.iterator(), 0)); + return StreamSupport.stream(Spliterators.spliteratorUnknownSize(l.iterator(), 0), false); } @Test(dataProvider = "StreamTestData", dataProviderClass = StreamTestDataProvider.class) @@ -150,7 +150,7 @@ public class SortedOpTest extends OpTestCase { } private IntStream unknownSizeIntStream(int[] a) { - return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(Spliterators.iterator(Arrays.spliterator(a)), 0)); + return StreamSupport.intStream(Spliterators.spliteratorUnknownSize(Spliterators.iterator(Arrays.spliterator(a)), 0), false); } @Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class) @@ -193,7 +193,7 @@ public class SortedOpTest extends OpTestCase { } private LongStream unknownSizeLongStream(long[] a) { - return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(Spliterators.iterator(Arrays.spliterator(a)), 0)); + return StreamSupport.longStream(Spliterators.spliteratorUnknownSize(Spliterators.iterator(Arrays.spliterator(a)), 0), false); } @Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class) @@ -236,7 +236,7 @@ public class SortedOpTest extends OpTestCase { } private DoubleStream unknownSizeDoubleStream(double[] a) { - return StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(Spliterators.iterator(Arrays.spliterator(a)), 0)); + return StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(Spliterators.iterator(Arrays.spliterator(a)), 0), false); } @Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class) diff --git a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java index bd111cfdb2..f3739784b3 100644 --- a/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java +++ b/jdk/test/java/util/stream/test/org/openjdk/tests/java/util/stream/StreamSpliteratorTest.java @@ -266,7 +266,7 @@ public class StreamSpliteratorTest extends OpTestCase { setContext("proxyEstimateSize", proxyEstimateSize); Spliterator sp = intermediateOp.apply(l.stream()).spliterator(); ProxyNoExactSizeSpliterator psp = new ProxyNoExactSizeSpliterator<>(sp, proxyEstimateSize); - Stream s = StreamSupport.parallelStream(psp); + Stream s = StreamSupport.stream(psp, true); terminalOp.accept(s); Assert.assertTrue(psp.splits > 0, String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", @@ -290,14 +290,14 @@ public class StreamSpliteratorTest extends OpTestCase { withData(data). stream((Stream in) -> { Stream out = f.apply(in); - return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); }). exercise(); withData(data). stream((Stream in) -> { Stream out = f.apply(in); - return StreamSupport.parallelStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.stream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); }). exercise(); } @@ -362,7 +362,7 @@ public class StreamSpliteratorTest extends OpTestCase { // @@@ Need way to obtain the target size Spliterator.OfInt sp = intermediateOp.apply(IntStream.range(0, 1000)).spliterator(); ProxyNoExactSizeSpliterator.OfInt psp = new ProxyNoExactSizeSpliterator.OfInt(sp, proxyEstimateSize); - IntStream s = StreamSupport.intParallelStream(psp); + IntStream s = StreamSupport.intStream(psp, true); terminalOp.accept(s); Assert.assertTrue(psp.splits > 0, String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", @@ -386,14 +386,14 @@ public class StreamSpliteratorTest extends OpTestCase { withData(data). stream(in -> { IntStream out = f.apply(in); - return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); }). exercise(); withData(data). stream((in) -> { IntStream out = f.apply(in); - return StreamSupport.intParallelStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.intStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); }). exercise(); } @@ -455,7 +455,7 @@ public class StreamSpliteratorTest extends OpTestCase { // @@@ Need way to obtain the target size Spliterator.OfLong sp = intermediateOp.apply(LongStream.range(0, 1000)).spliterator(); ProxyNoExactSizeSpliterator.OfLong psp = new ProxyNoExactSizeSpliterator.OfLong(sp, proxyEstimateSize); - LongStream s = StreamSupport.longParallelStream(psp); + LongStream s = StreamSupport.longStream(psp, true); terminalOp.accept(s); Assert.assertTrue(psp.splits > 0, String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", @@ -479,14 +479,14 @@ public class StreamSpliteratorTest extends OpTestCase { withData(data). stream(in -> { LongStream out = f.apply(in); - return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); }). exercise(); withData(data). stream((in) -> { LongStream out = f.apply(in); - return StreamSupport.longParallelStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.longStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); }). exercise(); } @@ -548,7 +548,7 @@ public class StreamSpliteratorTest extends OpTestCase { // @@@ Need way to obtain the target size Spliterator.OfDouble sp = intermediateOp.apply(IntStream.range(0, 1000).asDoubleStream()).spliterator(); ProxyNoExactSizeSpliterator.OfDouble psp = new ProxyNoExactSizeSpliterator.OfDouble(sp, proxyEstimateSize); - DoubleStream s = StreamSupport.doubleParallelStream(psp); + DoubleStream s = StreamSupport.doubleStream(psp, true); terminalOp.accept(s); Assert.assertTrue(psp.splits > 0, String.format("Number of splits should be greater that zero when proxyEstimateSize is %s", @@ -572,14 +572,14 @@ public class StreamSpliteratorTest extends OpTestCase { withData(data). stream(in -> { DoubleStream out = f.apply(in); - return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), false); }). exercise(); withData(data). stream((in) -> { DoubleStream out = f.apply(in); - return StreamSupport.doubleParallelStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out)); + return StreamSupport.doubleStream(() -> out.spliterator(), OpTestCase.getStreamFlags(out), true); }). exercise(); } -- GitLab