jdk/src/share/classes/java/util/stream/StreamSupport.java
author henryjen
Tue, 03 Sep 2013 12:16:01 -0700
changeset 19800 6e1fef53ea55
parent 19047 08210fe86260
child 19850 93b368e54c1c
permissions -rw-r--r--
8017513: Support for closeable streams 8022237: j.u.s.BaseStream.onClose() has an issue in implementation or requires spec clarification 8022572: Same exception instances thrown from j.u.stream.Stream.onClose() handlers are not listed as suppressed Summary: BaseStream implements AutoCloseable; Remove CloseableStream and DelegatingStream Reviewed-by: alanb, mduigou, psandoz Contributed-by: brian.goetz@oracle.com
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
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    35
 * of their data structures; most static stream methods for end users are in
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    36
 * {@link Streams}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    37
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    38
 * <p>Unless otherwise stated, streams are created as sequential
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    39
 * streams.  A sequential stream can be transformed into a parallel stream by
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    40
 * calling the {@code parallel()} method on the created stream.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    41
 *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    42
 * @since 1.8
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    43
 */
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    44
public final class StreamSupport {
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    45
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    46
    // Suppresses default constructor, ensuring non-instantiability.
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    47
    private StreamSupport() {}
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    48
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    49
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    50
     * 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
    51
     * {@code Spliterator}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    52
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    53
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    54
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    55
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    56
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    57
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    58
     * <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
    59
     * {@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
    60
     * to reduce the scope of potential interference with the source.  See
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    61
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    62
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    63
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    64
     * @param <T> the type of stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    65
     * @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
    66
     * @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
    67
     *        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
    68
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    69
     * @return a new sequential or parallel {@code Stream}
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    70
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    71
    public static <T> Stream<T> stream(Spliterator<T> spliterator, boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    72
        Objects.requireNonNull(spliterator);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    73
        return new ReferencePipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    74
                                            StreamOpFlag.fromCharacteristics(spliterator),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    75
                                            parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    76
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    77
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    78
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
    79
     * 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
    80
     * {@code Supplier} of {@code Spliterator}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    81
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    82
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    83
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    84
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    85
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    86
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    87
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
    88
     * <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
    89
     * 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
    90
     * instead.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    91
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    92
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    93
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    94
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    95
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    96
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    97
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    98
     *
19047
08210fe86260 8021408: Fix misc doclint issues in java.util and java.io
darcy
parents: 18822
diff changeset
    99
     * @param <T> the type of stream elements
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   100
     * @param supplier a {@code Supplier} of a {@code Spliterator}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   101
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   102
     *        {@code Spliterator}.  The characteristics must be equal to
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   103
     *        {@code supplier.get().characteristics()}.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   104
     * @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
   105
     *        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
   106
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   107
     * @return a new sequential or parallel {@code Stream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   108
     * @see #stream(java.util.Spliterator, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   109
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   110
    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
   111
                                       int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   112
                                       boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   113
        Objects.requireNonNull(supplier);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   114
        return new ReferencePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   115
                                            StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   116
                                            parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   117
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   118
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   119
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   120
     * 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
   121
     * {@code Spliterator.OfInt}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   122
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   123
     * <p>The spliterator is only traversed, split, or queried for estimated size
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   124
     * after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   125
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   126
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   127
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   128
     * <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
   129
     * {@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
   130
     * used to reduce the scope of potential interference with the source.  See
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   131
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   132
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   133
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   134
     * @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
   135
     * @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
   136
     *        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
   137
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   138
     * @return a new sequential or parallel {@code IntStream}
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   139
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   140
    public static IntStream intStream(Spliterator.OfInt spliterator, boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   141
        return new IntPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   142
                                      StreamOpFlag.fromCharacteristics(spliterator),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   143
                                      parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   144
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   145
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   146
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   147
     * 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
   148
     * {@code Supplier} of {@code Spliterator.OfInt}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   149
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   150
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   151
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   152
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   153
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   154
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   155
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   156
     * <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
   157
     * 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
   158
     * instead.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   159
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   160
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   161
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   162
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   163
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   164
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   165
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   166
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   167
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfInt}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   168
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   169
     *        {@code Spliterator.OfInt}.  The characteristics must be equal to
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   170
     *        {@code supplier.get().characteristics()}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   171
     * @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
   172
     *        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
   173
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   174
     * @return a new sequential or parallel {@code IntStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   175
     * @see #intStream(java.util.Spliterator.OfInt, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   176
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   177
    public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   178
                                      int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   179
                                      boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   180
        return new IntPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   181
                                      StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   182
                                      parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   183
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   184
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   185
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   186
     * 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
   187
     * {@code Spliterator.OfLong}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   188
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   189
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   190
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   191
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   192
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   193
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   194
     * <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
   195
     * {@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
   196
     * used to reduce the scope of potential interference with the source.  See
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   197
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   198
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   199
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   200
     * @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
   201
     * @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
   202
     *        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
   203
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   204
     * @return a new sequential or parallel {@code LongStream}
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   205
     */
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   206
    public static LongStream longStream(Spliterator.OfLong spliterator,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   207
                                        boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   208
        return new LongPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   209
                                       StreamOpFlag.fromCharacteristics(spliterator),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   210
                                       parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   211
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   212
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   213
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   214
     * 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
   215
     * {@code Supplier} of {@code Spliterator.OfLong}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   216
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   217
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   218
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   219
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   220
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   221
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   222
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   223
     * <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
   224
     * 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
   225
     * instead.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   226
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   227
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   228
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   229
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   230
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   231
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   232
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   233
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   234
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfLong}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   235
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   236
     *        {@code Spliterator.OfLong}.  The characteristics must be equal to
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   237
     *        {@code supplier.get().characteristics()}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   238
     * @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
   239
     *        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
   240
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   241
     * @return a new sequential or parallel {@code LongStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   242
     * @see #longStream(java.util.Spliterator.OfLong, boolean)
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   243
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   244
    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
   245
                                        int characteristics,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   246
                                        boolean parallel) {
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   247
        return new LongPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   248
                                       StreamOpFlag.fromCharacteristics(characteristics),
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   249
                                       parallel);
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   250
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   251
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   252
    /**
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   253
     * 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
   254
     * {@code Spliterator.OfDouble}.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   255
     *
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   256
     * <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
   257
     * after the terminal operation of the stream pipeline commences.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   258
     *
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   259
     * <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
   260
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   261
     * <a href="../Spliterator.html#binding">late-binding</a>.  Otherwise,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   262
     * {@link #doubleStream(java.util.function.Supplier, int, boolean)} should
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   263
     * be used to reduce the scope of potential interference with the source.  See
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   264
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   265
     * more details.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   266
     *
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   267
     * @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
   268
     * @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
   269
     *        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
   270
     *        stream.
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   271
     * @return a new sequential or parallel {@code DoubleStream}
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   272
     */
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   273
    public static DoubleStream doubleStream(Spliterator.OfDouble spliterator,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   274
                                            boolean parallel) {
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   275
        return new DoublePipeline.Head<>(spliterator,
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   276
                                         StreamOpFlag.fromCharacteristics(spliterator),
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   277
                                         parallel);
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
    /**
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   281
     * 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
   282
     * {@code Supplier} of {@code Spliterator.OfDouble}.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   283
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   284
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   285
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   286
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   287
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   288
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   289
     * or {@code CONCURRENT}, or that are
17931
765c1e9a498a 8014731: j.u.stream.StreamSupport class has default constructor generated
psandoz
parents: 17182
diff changeset
   290
     * <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
   291
     * 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
   292
     * instead.
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   293
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   294
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   295
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   296
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   297
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   298
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   299
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   300
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   301
     * @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   302
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   303
     *        {@code Spliterator.OfDouble}.  The characteristics must be equal to
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 17931
diff changeset
   304
     *        {@code supplier.get().characteristics()}
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
}