jdk/src/share/classes/java/util/stream/StreamSupport.java
author briangoetz
Sat, 20 Apr 2013 18:53:26 -0400
changeset 17195 e897ad52979e
parent 17182 b786c0de868c
child 17931 765c1e9a498a
permissions -rw-r--r--
8012650: Arrays streams methods 8011918: java.util.stream.Streams Reviewed-by: alanb, mduigou, darcy, henryjen Contributed-by: brian.goetz@oracle.com, paul.sandoz@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17182
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     1
/*
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
 */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    44
public class StreamSupport {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    45
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    46
     * Creates a new sequential {@code Stream} from a {@code Spliterator}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    47
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    48
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    49
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    50
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    51
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    52
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    53
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    54
     * {@link #stream(Supplier, int)} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    55
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    56
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    57
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    58
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    59
     * @param <T> the type of stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    60
     * @param spliterator a {@code Spliterator} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    61
     * @return a new sequential {@code Stream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    62
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    63
    public static <T> Stream<T> stream(Spliterator<T> spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    64
        Objects.requireNonNull(spliterator);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    65
        return new ReferencePipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    66
                                            StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    67
                                            false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    68
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    69
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    70
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    71
     * Creates a new parallel {@code Stream} from a {@code Spliterator}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    72
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    73
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    74
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    75
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    76
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    77
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    78
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    79
     * {@link #stream(Supplier, int)} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    80
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    81
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    82
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    83
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    84
     * @param <T> the type of stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    85
     * @param spliterator a {@code Spliterator} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    86
     * @return a new parallel {@code Stream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    87
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    88
    public static <T> Stream<T> parallelStream(Spliterator<T> spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    89
        Objects.requireNonNull(spliterator);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    90
        return new ReferencePipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    91
                                            StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    92
                                            true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    93
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    94
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    95
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    96
     * Creates a new sequential {@code Stream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    97
     * {@code Spliterator}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    98
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
    99
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   100
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   101
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   102
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   103
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   104
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   105
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   106
     * more efficient to use {@link #stream(java.util.Spliterator)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   107
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   108
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   109
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   110
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   111
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   112
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   113
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   114
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   115
     * @param <T> the type of stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   116
     * @param supplier a {@code Supplier} of a {@code Spliterator}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   117
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   118
     *        {@code Spliterator}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   119
     *        {@code source.get().getCharacteristics()}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   120
     * @return a new sequential {@code Stream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   121
     * @see #stream(Spliterator)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   122
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   123
    public static <T> Stream<T> stream(Supplier<? extends Spliterator<T>> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   124
                                      int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   125
        Objects.requireNonNull(supplier);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   126
        return new ReferencePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   127
                                            StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   128
                                            false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   129
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   130
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   131
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   132
     * Creates a new parallel {@code Stream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   133
     * {@code Spliterator}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   134
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   135
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   136
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   137
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   138
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   139
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   140
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   141
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   142
     * more efficient to use {@link #stream(Spliterator)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   143
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   144
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   145
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   146
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   147
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   148
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   149
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   150
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   151
     * @param <T> the type of stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   152
     * @param supplier a {@code Supplier} of a {@code Spliterator}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   153
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   154
     *        {@code Spliterator}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   155
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   156
     * @return a new parallel {@code Stream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   157
     * @see #parallelStream(Spliterator)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   158
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   159
    public static <T> Stream<T> parallelStream(Supplier<? extends Spliterator<T>> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   160
                                              int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   161
        Objects.requireNonNull(supplier);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   162
        return new ReferencePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   163
                                            StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   164
                                            true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   165
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   166
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   167
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   168
     * Creates a new sequential {@code IntStream} from a {@code Spliterator.OfInt}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   169
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   170
     * <p>The spliterator is only traversed, split, or queried for estimated size
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   171
     * after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   172
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   173
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   174
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   175
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   176
     * {@link #stream(Supplier, int)}} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   177
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   178
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   179
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   180
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   181
     * @param spliterator a {@code Spliterator.OfInt} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   182
     * @return a new sequential {@code IntStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   183
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   184
    public static IntStream intStream(Spliterator.OfInt spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   185
        return new IntPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   186
                                      StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   187
                                      false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   188
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   189
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   190
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   191
     * Creates a new parallel {@code IntStream} from a {@code Spliterator.OfInt}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   192
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   193
     * <p>he spliterator is only traversed, split, or queried for estimated size
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   194
     * after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   195
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   196
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   197
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   198
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   199
     * {@link #stream(Supplier, int)}} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   200
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   201
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   202
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   203
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   204
     * @param spliterator a {@code Spliterator.OfInt} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   205
     * @return a new parallel {@code IntStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   206
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   207
    public static IntStream intParallelStream(Spliterator.OfInt spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   208
        return new IntPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   209
                                      StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   210
                                      true);
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
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   214
     * Creates a new sequential {@code IntStream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   215
     * {@code Spliterator.OfInt}.
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
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   223
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   224
     * more efficient to use {@link #intStream(Spliterator.OfInt)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   225
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   226
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   227
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   228
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   229
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   230
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   231
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   232
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   233
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfInt}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   234
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   235
     *        {@code Spliterator.OfInt}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   236
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   237
     * @return a new sequential {@code IntStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   238
     * @see #intStream(Spliterator.OfInt)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   239
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   240
    public static IntStream intStream(Supplier<? extends Spliterator.OfInt> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   241
                                      int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   242
        return new IntPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   243
                                      StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   244
                                      false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   245
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   246
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   247
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   248
     * Creates a new parallel {@code IntStream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   249
     * {@code Spliterator.OfInt}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   250
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   251
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   252
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   253
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   254
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   255
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   256
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   257
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   258
     * more efficient to use {@link #intStream(Spliterator.OfInt)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   259
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   260
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   261
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   262
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   263
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   264
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   265
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   266
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   267
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfInt}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   268
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   269
     *        {@code Spliterator.OfInt}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   270
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   271
     * @return a new parallel {@code IntStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   272
     * @see #intParallelStream(Spliterator.OfInt)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   273
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   274
    public static IntStream intParallelStream(Supplier<? extends Spliterator.OfInt> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   275
                                              int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   276
        return new IntPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   277
                                      StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   278
                                      true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   279
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   280
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   281
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   282
     * Creates a new sequential {@code LongStream} from a {@code Spliterator.OfLong}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   283
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   284
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   285
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   286
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   287
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   288
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   289
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   290
     * {@link #stream(Supplier, int)} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   291
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   292
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   293
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   294
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   295
     * @param spliterator a {@code Spliterator.OfLong} describing the stream
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   296
     * elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   297
     * @return a new sequential {@code LongStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   298
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   299
    public static LongStream longStream(Spliterator.OfLong spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   300
        return new LongPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   301
                                       StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   302
                                       false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   303
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   304
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   305
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   306
     * Creates a new parallel {@code LongStream} from a {@code Spliterator.OfLong}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   307
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   308
     * <p>The spliterator is only traversed, split, or queried for estimated
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   309
     * size after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   310
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   311
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   312
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   313
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   314
     * {@link #stream(Supplier, int)} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   315
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   316
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   317
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   318
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   319
     * @param spliterator a {@code Spliterator.OfLong} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   320
     * @return a new parallel {@code LongStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   321
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   322
    public static LongStream longParallelStream(Spliterator.OfLong spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   323
        return new LongPipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   324
                                       StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   325
                                       true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   326
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   327
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   328
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   329
     * Creates a new sequential {@code LongStream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   330
     * {@code Spliterator.OfLong}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   331
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   332
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   333
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   334
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   335
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   336
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   337
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   338
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   339
     * more efficient to use {@link #longStream(Spliterator.OfLong)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   340
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   341
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   342
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   343
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   344
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   345
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   346
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   347
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   348
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfLong}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   349
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   350
     *        {@code Spliterator.OfLong}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   351
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   352
     * @return a new sequential {@code LongStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   353
     * @see #longStream(Spliterator.OfLong)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   354
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   355
    public static LongStream longStream(Supplier<? extends Spliterator.OfLong> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   356
                                        int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   357
        return new LongPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   358
                                       StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   359
                                       false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   360
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   361
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   362
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   363
     * Creates a new parallel {@code LongStream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   364
     * {@code Spliterator.OfLong}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   365
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   366
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   367
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   368
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   369
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   370
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   371
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   372
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   373
     * more efficient to use {@link #longStream(Spliterator.OfLong)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   374
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   375
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   376
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   377
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   378
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   379
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   380
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   381
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   382
     * @param supplier A {@code Supplier} of a {@code Spliterator.OfLong}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   383
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   384
     *        {@code Spliterator.OfLong}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   385
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   386
     * @return A new parallel {@code LongStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   387
     * @see #longParallelStream(Spliterator.OfLong)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   388
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   389
    public static LongStream longParallelStream(Supplier<? extends Spliterator.OfLong> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   390
                                                int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   391
        return new LongPipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   392
                                       StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   393
                                       true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   394
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   395
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   396
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   397
     * Creates a new sequential {@code DoubleStream} from a
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   398
     * {@code Spliterator.OfDouble}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   399
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   400
     * <p>The spliterator is only traversed, split, or queried for estimated size
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   401
     * after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   402
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   403
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   404
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   405
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   406
     * {@link #stream(Supplier, int)} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   407
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   408
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   409
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   410
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   411
     * @param spliterator A {@code Spliterator.OfDouble} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   412
     * @return A new sequential {@code DoubleStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   413
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   414
    public static DoubleStream doubleStream(Spliterator.OfDouble spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   415
        return new DoublePipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   416
                                         StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   417
                                         false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   418
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   419
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   420
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   421
     * Creates a new parallel {@code DoubleStream} from a
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   422
     * {@code Spliterator.OfDouble}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   423
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   424
     * <p>The spliterator is only traversed, split, or queried for estimated size
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   425
     * after the terminal operation of the stream pipeline commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   426
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   427
     * <p>It is strongly recommended the spliterator report a characteristic of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   428
     * {@code IMMUTABLE} or {@code CONCURRENT}, or be
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   429
     * <a href="Spliterator.html#binding">late-binding</a>.  Otherwise,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   430
     * {@link #stream(Supplier, int)} should be used to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   431
     * reduce the scope of potential interference with the source.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   432
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   433
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   434
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   435
     * @param spliterator A {@code Spliterator.OfDouble} describing the stream elements
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   436
     * @return A new parallel {@code DoubleStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   437
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   438
    public static DoubleStream doubleParallelStream(Spliterator.OfDouble spliterator) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   439
        return new DoublePipeline.Head<>(spliterator,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   440
                                         StreamOpFlag.fromCharacteristics(spliterator),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   441
                                         true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   442
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   443
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   444
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   445
     * Creates a new sequential {@code DoubleStream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   446
     * {@code Spliterator.OfDouble}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   447
     * <p>
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   448
     * The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   449
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   450
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   451
     * <p>
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   452
     * For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   453
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   454
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   455
     * more efficient to use {@link #doubleStream(Spliterator.OfDouble)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   456
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   457
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   458
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   459
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   460
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   461
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   462
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   463
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   464
     * @param supplier A {@code Supplier} of a {@code Spliterator.OfDouble}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   465
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   466
     *        {@code Spliterator.OfDouble}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   467
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   468
     * @return A new sequential {@code DoubleStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   469
     * @see #doubleStream(Spliterator.OfDouble)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   470
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   471
    public static DoubleStream doubleStream(Supplier<? extends Spliterator.OfDouble> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   472
                                            int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   473
        return new DoublePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   474
                                         StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   475
                                         false);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   476
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   477
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   478
    /**
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   479
     * Creates a new parallel {@code DoubleStream} from a {@code Supplier} of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   480
     * {@code Spliterator.OfDouble}.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   481
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   482
     * <p>The {@link Supplier#get()} method will be invoked on the supplier no
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   483
     * more than once, and after the terminal operation of the stream pipeline
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   484
     * commences.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   485
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   486
     * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   487
     * or {@code CONCURRENT}, or that are
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   488
     * <a href="Spliterator.html#binding">late-binding</a>, it is likely
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   489
     * more efficient to use {@link #doubleStream(Spliterator.OfDouble)} instead.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   490
     * The use of a {@code Supplier} in this form provides a level of
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   491
     * indirection that reduces the scope of potential interference with the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   492
     * source.  Since the supplier is only invoked after the terminal operation
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   493
     * commences, any modifications to the source up to the start of the
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   494
     * terminal operation are reflected in the stream result.  See
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   495
     * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   496
     * more details.
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   497
     *
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   498
     * @param supplier a {@code Supplier} of a {@code Spliterator.OfDouble}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   499
     * @param characteristics Spliterator characteristics of the supplied
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   500
     *        {@code Spliterator.OfDouble}.  The characteristics must be equal to
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   501
     *        {@code source.get().getCharacteristics()}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   502
     * @return a new parallel {@code DoubleStream}
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   503
     * @see #doubleParallelStream(Spliterator.OfDouble)
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   504
     */
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   505
    public static DoubleStream doubleParallelStream(Supplier<? extends Spliterator.OfDouble> supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   506
                                                    int characteristics) {
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   507
        return new DoublePipeline.Head<>(supplier,
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   508
                                         StreamOpFlag.fromCharacteristics(characteristics),
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   509
                                         true);
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   510
    }
b786c0de868c 8011920: Main streams implementation
mduigou
parents:
diff changeset
   511
}