mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8181175: Stream.concat behaves like terminal operation
Reviewed-by: smarks, briangoetz, dfuchs
This commit is contained in:
parent
625c3fd013
commit
e0fe688373
4 changed files with 65 additions and 1 deletions
|
@ -1089,11 +1089,27 @@ public interface DoubleStream extends BaseStream<Double, DoubleStream> {
|
||||||
* streams is parallel. When the resulting stream is closed, the close
|
* streams is parallel. When the resulting stream is closed, the close
|
||||||
* handlers for both input streams are invoked.
|
* handlers for both input streams are invoked.
|
||||||
*
|
*
|
||||||
|
* <p>This method operates on the two input streams and binds each stream
|
||||||
|
* to its source. As a result subsequent modifications to an input stream
|
||||||
|
* source may not be reflected in the concatenated stream result.
|
||||||
|
*
|
||||||
* @implNote
|
* @implNote
|
||||||
* Use caution when constructing streams from repeated concatenation.
|
* Use caution when constructing streams from repeated concatenation.
|
||||||
* Accessing an element of a deeply concatenated stream can result in deep
|
* Accessing an element of a deeply concatenated stream can result in deep
|
||||||
* call chains, or even {@code StackOverflowError}.
|
* call chains, or even {@code StackOverflowError}.
|
||||||
*
|
*
|
||||||
|
* @apiNote
|
||||||
|
* To preserve optimization opportunities this method binds each stream to
|
||||||
|
* its source and accepts only two streams as parameters. For example, the
|
||||||
|
* exact size of the concatenated stream source can be computed if the exact
|
||||||
|
* size of each input stream source is known.
|
||||||
|
* To concatenate more streams without binding, or without nested calls to
|
||||||
|
* this method, try creating a stream of streams and flat-mapping with the
|
||||||
|
* identity function, for example:
|
||||||
|
* <pre>{@code
|
||||||
|
* DoubleStream concat = Stream.of(s1, s2, s3, s4).flatMapToDouble(s -> s);
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
* @param a the first stream
|
* @param a the first stream
|
||||||
* @param b the second stream
|
* @param b the second stream
|
||||||
* @return the concatenation of the two input streams
|
* @return the concatenation of the two input streams
|
||||||
|
|
|
@ -1081,11 +1081,27 @@ public interface IntStream extends BaseStream<Integer, IntStream> {
|
||||||
* streams is parallel. When the resulting stream is closed, the close
|
* streams is parallel. When the resulting stream is closed, the close
|
||||||
* handlers for both input streams are invoked.
|
* handlers for both input streams are invoked.
|
||||||
*
|
*
|
||||||
|
* <p>This method operates on the two input streams and binds each stream
|
||||||
|
* to its source. As a result subsequent modifications to an input stream
|
||||||
|
* source may not be reflected in the concatenated stream result.
|
||||||
|
*
|
||||||
* @implNote
|
* @implNote
|
||||||
* Use caution when constructing streams from repeated concatenation.
|
* Use caution when constructing streams from repeated concatenation.
|
||||||
* Accessing an element of a deeply concatenated stream can result in deep
|
* Accessing an element of a deeply concatenated stream can result in deep
|
||||||
* call chains, or even {@code StackOverflowError}.
|
* call chains, or even {@code StackOverflowError}.
|
||||||
*
|
*
|
||||||
|
* @apiNote
|
||||||
|
* To preserve optimization opportunities this method binds each stream to
|
||||||
|
* its source and accepts only two streams as parameters. For example, the
|
||||||
|
* exact size of the concatenated stream source can be computed if the exact
|
||||||
|
* size of each input stream source is known.
|
||||||
|
* To concatenate more streams without binding, or without nested calls to
|
||||||
|
* this method, try creating a stream of streams and flat-mapping with the
|
||||||
|
* identity function, for example:
|
||||||
|
* <pre>{@code
|
||||||
|
* IntStream concat = Stream.of(s1, s2, s3, s4).flatMapToInt(s -> s);
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
* @param a the first stream
|
* @param a the first stream
|
||||||
* @param b the second stream
|
* @param b the second stream
|
||||||
* @return the concatenation of the two input streams
|
* @return the concatenation of the two input streams
|
||||||
|
|
|
@ -1086,11 +1086,27 @@ public interface LongStream extends BaseStream<Long, LongStream> {
|
||||||
* streams is parallel. When the resulting stream is closed, the close
|
* streams is parallel. When the resulting stream is closed, the close
|
||||||
* handlers for both input streams are invoked.
|
* handlers for both input streams are invoked.
|
||||||
*
|
*
|
||||||
|
* <p>This method operates on the two input streams and binds each stream
|
||||||
|
* to its source. As a result subsequent modifications to an input stream
|
||||||
|
* source may not be reflected in the concatenated stream result.
|
||||||
|
*
|
||||||
* @implNote
|
* @implNote
|
||||||
* Use caution when constructing streams from repeated concatenation.
|
* Use caution when constructing streams from repeated concatenation.
|
||||||
* Accessing an element of a deeply concatenated stream can result in deep
|
* Accessing an element of a deeply concatenated stream can result in deep
|
||||||
* call chains, or even {@code StackOverflowError}.
|
* call chains, or even {@code StackOverflowError}.
|
||||||
*
|
*
|
||||||
|
* @apiNote
|
||||||
|
* To preserve optimization opportunities this method binds each stream to
|
||||||
|
* its source and accepts only two streams as parameters. For example, the
|
||||||
|
* exact size of the concatenated stream source can be computed if the exact
|
||||||
|
* size of each input stream source is known.
|
||||||
|
* To concatenate more streams without binding, or without nested calls to
|
||||||
|
* this method, try creating a stream of streams and flat-mapping with the
|
||||||
|
* identity function, for example:
|
||||||
|
* <pre>{@code
|
||||||
|
* LongStream concat = Stream.of(s1, s2, s3, s4).flatMapToLong(s -> s);
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
* @param a the first stream
|
* @param a the first stream
|
||||||
* @param b the second stream
|
* @param b the second stream
|
||||||
* @return the concatenation of the two input streams
|
* @return the concatenation of the two input streams
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -1341,6 +1341,10 @@ public interface Stream<T> extends BaseStream<T, Stream<T>> {
|
||||||
* streams is parallel. When the resulting stream is closed, the close
|
* streams is parallel. When the resulting stream is closed, the close
|
||||||
* handlers for both input streams are invoked.
|
* handlers for both input streams are invoked.
|
||||||
*
|
*
|
||||||
|
* <p>This method operates on the two input streams and binds each stream
|
||||||
|
* to its source. As a result subsequent modifications to an input stream
|
||||||
|
* source may not be reflected in the concatenated stream result.
|
||||||
|
*
|
||||||
* @implNote
|
* @implNote
|
||||||
* Use caution when constructing streams from repeated concatenation.
|
* Use caution when constructing streams from repeated concatenation.
|
||||||
* Accessing an element of a deeply concatenated stream can result in deep
|
* Accessing an element of a deeply concatenated stream can result in deep
|
||||||
|
@ -1349,6 +1353,18 @@ public interface Stream<T> extends BaseStream<T, Stream<T>> {
|
||||||
* <p>Subsequent changes to the sequential/parallel execution mode of the
|
* <p>Subsequent changes to the sequential/parallel execution mode of the
|
||||||
* returned stream are not guaranteed to be propagated to the input streams.
|
* returned stream are not guaranteed to be propagated to the input streams.
|
||||||
*
|
*
|
||||||
|
* @apiNote
|
||||||
|
* To preserve optimization opportunities this method binds each stream to
|
||||||
|
* its source and accepts only two streams as parameters. For example, the
|
||||||
|
* exact size of the concatenated stream source can be computed if the exact
|
||||||
|
* size of each input stream source is known.
|
||||||
|
* To concatenate more streams without binding, or without nested calls to
|
||||||
|
* this method, try creating a stream of streams and flat-mapping with the
|
||||||
|
* identity function, for example:
|
||||||
|
* <pre>{@code
|
||||||
|
* Stream<T> concat = Stream.of(s1, s2, s3, s4).flatMap(s -> s);
|
||||||
|
* }</pre>
|
||||||
|
*
|
||||||
* @param <T> The type of stream elements
|
* @param <T> The type of stream elements
|
||||||
* @param a the first stream
|
* @param a the first stream
|
||||||
* @param b the second stream
|
* @param b the second stream
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue