src/share/classes/java/util/stream/IntStream.java

Print this page
rev 7532 : 8015315: Stream.concat methods
Contributed-by: brian.goetz@oracle.com, henry.jen@oracle.com


 783      * @apiNote
 784      * <p>An equivalent sequence of increasing values can be produced
 785      * sequentially using a {@code for} loop as follows:
 786      * <pre>{@code
 787      *     for (int i = startInclusive; i <= endInclusive ; i++) { ... }
 788      * }</pre>
 789      *
 790      * @param startInclusive the (inclusive) initial value
 791      * @param endInclusive the inclusive upper bound
 792      * @return a sequential {@code IntStream} for the range of {@code int}
 793      *         elements
 794      */
 795     public static IntStream rangeClosed(int startInclusive, int endInclusive) {
 796         if (startInclusive > endInclusive) {
 797             return empty();
 798         } else {
 799             return StreamSupport.intStream(
 800                     new Streams.RangeIntSpliterator(startInclusive, endInclusive, true));
 801         }
 802     }






















 803 }


 783      * @apiNote
 784      * <p>An equivalent sequence of increasing values can be produced
 785      * sequentially using a {@code for} loop as follows:
 786      * <pre>{@code
 787      *     for (int i = startInclusive; i <= endInclusive ; i++) { ... }
 788      * }</pre>
 789      *
 790      * @param startInclusive the (inclusive) initial value
 791      * @param endInclusive the inclusive upper bound
 792      * @return a sequential {@code IntStream} for the range of {@code int}
 793      *         elements
 794      */
 795     public static IntStream rangeClosed(int startInclusive, int endInclusive) {
 796         if (startInclusive > endInclusive) {
 797             return empty();
 798         } else {
 799             return StreamSupport.intStream(
 800                     new Streams.RangeIntSpliterator(startInclusive, endInclusive, true));
 801         }
 802     }
 803 
 804     /**
 805      * Creates a lazy concatenated {@code IntStream} whose elements are all the
 806      * elements of a first {@code IntStream} succeeded by all the elements of the
 807      * second {@code IntStream}. The resulting stream is ordered if both
 808      * of the input streams are ordered, and parallel if either of the input
 809      * streams is parallel.
 810      *
 811      * @param a the first stream
 812      * @param b the second stream to concatenate on to end of the first stream
 813      * @return the concatenation of the two streams
 814      */
 815     public static IntStream concat(IntStream a, IntStream b) {
 816         Objects.requireNonNull(a);
 817         Objects.requireNonNull(b);
 818 
 819         Spliterator.OfInt split = new Streams.ConcatSpliterator.OfInt(
 820                 a.spliterator(), b.spliterator());
 821         return (a.isParallel() || b.isParallel())
 822                ? StreamSupport.intParallelStream(split)
 823                : StreamSupport.intStream(split);
 824     }
 825 }