jdk/src/share/classes/java/util/stream/StreamSupport.java
author michaelm
Wed, 11 Dec 2013 15:27:06 -0800
changeset 22291 6106c1f013f1
parent 21339 20e8b81964d5
permissions -rw-r--r--
8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream Reviewed-by: mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     1
/*
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 18822
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     4
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    10
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    15
 * accompanied this code).
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    16
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    20
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    23
 * questions.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    24
 */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    25
package java.util.stream;
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    26
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    27
import java.util.Objects;
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    28
import java.util.Spliterator;
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    29
import java.util.function.Supplier;
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    30
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    31
/**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    32
 * Low-level utility methods for creating and manipulating streams.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    33
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    34
 * <p>This class is mostly for library writers presenting stream views
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
    35
 * of data structures; most static stream methods intended for end users are in
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
    36
 * the various {@code Stream} classes.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    37
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    38
 * @since 1.8
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    39
 */
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    40
public final class StreamSupport {
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    41
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    42
    // Suppresses default constructor, ensuring non-instantiability.
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    43
    private StreamSupport() {}
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    44
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    45
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    46
     * Creates a new sequential or parallel {@code Stream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    47
     * {@code Spliterator}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    48
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    49
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    50
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    51
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    52
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    53
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    54
     * <a href="../Spliterator.html#binding">late-binding</a>.  Otherwise,
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    55
     * {@link #stream(java.util.function.Supplier, int, boolean)} should be used
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    56
     * to reduce the scope of potential interference with the source.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
    57
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    58
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    59
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    60
     * @param <T> the type of stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    61
     * @param spliterator a {@code Spliterator} describing the stream elements
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    62
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    63
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    64
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    65
     * @return a new sequential or parallel {@code Stream}
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    66
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    67
    public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    68
        Objects.requireNonNull(spliterator);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    69
        return new ReferencePipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    70
                                            StreamOpFlag.fromCharacteristics(spliterator),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    71
                                            parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    72
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    73
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    74
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    75
     * Creates a new sequential or parallel {@code Stream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    76
     * {@code Supplier} of {@code Spliterator}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    77
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    78
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
    79
     * more than once, and only after the terminal operation of the stream pipeline
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    80
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    81
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    82
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    83
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    84
     * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    85
     * more efficient to use {@link #stream(java.util.Spliterator, boolean)}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    86
     * instead.
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
    87
     * <p>The use of a {@code Supplier} in this form provides a level of
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    88
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    89
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    90
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    91
     * terminal operation are reflected in the stream result.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
    92
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    93
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    94
     *
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 18822
diff changeset
    95
     * @param <T> the type of stream elements
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    96
     * @param supplier a {@code Supplier} of a {@code Spliterator}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    97
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    98
     *        {@code Spliterator}.  The characteristics must be equal to
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
    99
     *        {@code supplier.get().characteristics()}, otherwise undefined
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   100
     *        behavior may occur when terminal operation commences.
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   101
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   102
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   103
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   104
     * @return a new sequential or parallel {@code Stream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   105
     * @see #stream(java.util.Spliterator, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   106
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   107
    public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   108
                                       int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   109
                                       boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   110
        Objects.requireNonNull(supplier);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   111
        return new ReferencePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   112
                                            StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   113
                                            parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   114
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   115
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   116
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   117
     * Creates a new sequential or parallel {@code IntStream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   118
     * {@code Spliterator.OfInt}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   119
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   120
     * <p>The spliterator is only traversed, split, or queried for estimated size
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   121
     * after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   122
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   123
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   124
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   125
     * <a href="../Spliterator.html#binding">late-binding</a>.  Otherwise,
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   126
     * {@link #intStream(java.util.function.Supplier, int, boolean)} should be
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   127
     * used to reduce the scope of potential interference with the source.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
   128
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   129
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   130
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   131
     * @param spliterator a {@code Spliterator.OfInt} describing the stream elements
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   132
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   133
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   134
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   135
     * @return a new sequential or parallel {@code IntStream}
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   136
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   137
    public static IntStream intStream(Spliterator.OfInt spliterator, boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   138
        return new IntPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   139
                                      StreamOpFlag.fromCharacteristics(spliterator),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   140
                                      parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   141
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   142
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   143
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   144
     * Creates a new sequential or parallel {@code IntStream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   145
     * {@code Supplier} of {@code Spliterator.OfInt}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   146
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   147
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
   148
     * more than once, and only after the terminal operation of the stream pipeline
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   149
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   150
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   151
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   152
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   153
     * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   154
     * more efficient to use {@link #intStream(java.util.Spliterator.OfInt, boolean)}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   155
     * instead.
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
   156
     * <p>The use of a {@code Supplier} in this form provides a level of
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   157
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   158
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   159
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   160
     * terminal operation are reflected in the stream result.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
   161
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   162
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   163
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   164
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfInt}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   165
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   166
     *        {@code Spliterator.OfInt}.  The characteristics must be equal to
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   167
     *        {@code supplier.get().characteristics()}, otherwise undefined
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   168
     *        behavior may occur when terminal operation commences.
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   169
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   170
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   171
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   172
     * @return a new sequential or parallel {@code IntStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   173
     * @see #intStream(java.util.Spliterator.OfInt, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   174
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   175
    public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   176
                                      int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   177
                                      boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   178
        return new IntPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   179
                                      StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   180
                                      parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   181
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   183
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   184
     * Creates a new sequential or parallel {@code LongStream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   185
     * {@code Spliterator.OfLong}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   186
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   187
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   188
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   189
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   190
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   191
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   192
     * <a href="../Spliterator.html#binding">late-binding</a>.  Otherwise,
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   193
     * {@link #longStream(java.util.function.Supplier, int, boolean)} should be
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   194
     * used to reduce the scope of potential interference with the source.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
   195
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   196
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   197
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   198
     * @param spliterator a {@code Spliterator.OfLong} describing the stream elements
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   199
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   200
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   201
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   202
     * @return a new sequential or parallel {@code LongStream}
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   203
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   204
    public static LongStream longStream(Spliterator.OfLong spliterator,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   205
                                        boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   206
        return new LongPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   207
                                       StreamOpFlag.fromCharacteristics(spliterator),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   208
                                       parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   209
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   210
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   211
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   212
     * Creates a new sequential or parallel {@code LongStream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   213
     * {@code Supplier} of {@code Spliterator.OfLong}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   214
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   215
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
   216
     * more than once, and only after the terminal operation of the stream pipeline
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   217
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   218
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   219
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   220
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   221
     * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   222
     * more efficient to use {@link #longStream(java.util.Spliterator.OfLong, boolean)}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   223
     * instead.
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
   224
     * <p>The use of a {@code Supplier} in this form provides a level of
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   225
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   226
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   227
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   228
     * terminal operation are reflected in the stream result.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
   229
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   230
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   231
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   232
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfLong}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   233
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   234
     *        {@code Spliterator.OfLong}.  The characteristics must be equal to
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   235
     *        {@code supplier.get().characteristics()}, otherwise undefined
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   236
     *        behavior may occur when terminal operation commences.
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   237
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   238
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   239
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   240
     * @return a new sequential or parallel {@code LongStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   241
     * @see #longStream(java.util.Spliterator.OfLong, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   242
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   243
    public static LongStream longStream(Supplier<? extends Spliterator.OfLong> supplier,
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   244
                                        int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   245
                                        boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   246
        return new LongPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   247
                                       StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   248
                                       parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   249
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   250
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   251
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   252
     * Creates a new sequential or parallel {@code DoubleStream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   253
     * {@code Spliterator.OfDouble}.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   254
     *
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   255
     * <p>The spliterator is only traversed, split, or queried for estimated size
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   256
     * after the terminal operation of the stream pipeline commences.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   257
     *
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   258
     * <p>It is strongly recommended the spliterator report a characteristic of
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   259
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   260
     * <a href="../Spliterator.html#binding">late-binding</a>.  Otherwise,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   261
     * {@link #doubleStream(java.util.function.Supplier, int, boolean)} should
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   262
     * be used to reduce the scope of potential interference with the source.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
   263
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   264
     * more details.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   265
     *
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   266
     * @param spliterator A {@code Spliterator.OfDouble} describing the stream elements
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   267
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   268
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   269
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   270
     * @return a new sequential or parallel {@code DoubleStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   271
     */
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   272
    public static DoubleStream doubleStream(Spliterator.OfDouble spliterator,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   273
                                            boolean parallel) {
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   274
        return new DoublePipeline.Head<>(spliterator,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   275
                                         StreamOpFlag.fromCharacteristics(spliterator),
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   276
                                         parallel);
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   277
    }
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   278
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   279
    /**
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   280
     * Creates a new sequential or parallel {@code DoubleStream} from a
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   281
     * {@code Supplier} of {@code Spliterator.OfDouble}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   282
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   283
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
   284
     * more than once, and only after the terminal operation of the stream pipeline
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   285
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   286
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   287
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   288
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   289
     * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   290
     * more efficient to use {@link #doubleStream(java.util.Spliterator.OfDouble, boolean)}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   291
     * instead.
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19047
diff changeset
   292
     * <p>The use of a {@code Supplier} in this form provides a level of
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   293
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   294
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   295
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   296
     * terminal operation are reflected in the stream result.  See
22291
6106c1f013f1 8029696: Broken doc links to package-summary.html#NonInterference in java.util.stream
michaelm
parents: 21339
diff changeset
   297
     * <a href="package-summary.html#NonInterference">Non-Interference</a> for
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   298
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   299
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   300
     * @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   301
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   302
     *        {@code Spliterator.OfDouble}.  The characteristics must be equal to
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   303
     *        {@code supplier.get().characteristics()}, otherwise undefined
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 19850
diff changeset
   304
     *        behavior may occur when terminal operation commences.
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   305
     * @param parallel if {@code true} then the returned stream is a parallel
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   306
     *        stream; if {@code false} the returned stream is a sequential
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   307
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   308
     * @return a new sequential or parallel {@code DoubleStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   309
     * @see #doubleStream(java.util.Spliterator.OfDouble, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   310
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   311
    public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> supplier,
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   312
                                            int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   313
                                            boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   314
        return new DoublePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   315
                                         StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   316
                                         parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   317
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   318
}