jdk/src/share/classes/java/util/stream/StreamSupport.java
changeset 19850 93b368e54c1c
parent 19047 08210fe86260
child 21339 20e8b81964d5
equal deleted inserted replaced
19849:49c0b1bda5db 19850:93b368e54c1c
    30 
    30 
    31 /**
    31 /**
    32  * Low-level utility methods for creating and manipulating streams.
    32  * Low-level utility methods for creating and manipulating streams.
    33  *
    33  *
    34  * <p>This class is mostly for library writers presenting stream views
    34  * <p>This class is mostly for library writers presenting stream views
    35  * of their data structures; most static stream methods for end users are in
    35  * of data structures; most static stream methods intended for end users are in
    36  * {@link Streams}.
    36  * the various {@code Stream} classes.
    37  *
       
    38  * <p>Unless otherwise stated, streams are created as sequential
       
    39  * streams.  A sequential stream can be transformed into a parallel stream by
       
    40  * calling the {@code parallel()} method on the created stream.
       
    41  *
    37  *
    42  * @since 1.8
    38  * @since 1.8
    43  */
    39  */
    44 public final class StreamSupport {
    40 public final class StreamSupport {
    45 
    41 
    78     /**
    74     /**
    79      * Creates a new sequential or parallel {@code Stream} from a
    75      * Creates a new sequential or parallel {@code Stream} from a
    80      * {@code Supplier} of {@code Spliterator}.
    76      * {@code Supplier} of {@code Spliterator}.
    81      *
    77      *
    82      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
    78      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
    83      * more than once, and after the terminal operation of the stream pipeline
    79      * more than once, and only after the terminal operation of the stream pipeline
    84      * commences.
    80      * commences.
    85      *
    81      *
    86      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
    82      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
    87      * or {@code CONCURRENT}, or that are
    83      * or {@code CONCURRENT}, or that are
    88      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
    84      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
    89      * more efficient to use {@link #stream(java.util.Spliterator, boolean)}
    85      * more efficient to use {@link #stream(java.util.Spliterator, boolean)}
    90      * instead.
    86      * instead.
    91      * The use of a {@code Supplier} in this form provides a level of
    87      * <p>The use of a {@code Supplier} in this form provides a level of
    92      * indirection that reduces the scope of potential interference with the
    88      * indirection that reduces the scope of potential interference with the
    93      * source.  Since the supplier is only invoked after the terminal operation
    89      * source.  Since the supplier is only invoked after the terminal operation
    94      * commences, any modifications to the source up to the start of the
    90      * commences, any modifications to the source up to the start of the
    95      * terminal operation are reflected in the stream result.  See
    91      * terminal operation are reflected in the stream result.  See
    96      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
    92      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
   146     /**
   142     /**
   147      * Creates a new sequential or parallel {@code IntStream} from a
   143      * Creates a new sequential or parallel {@code IntStream} from a
   148      * {@code Supplier} of {@code Spliterator.OfInt}.
   144      * {@code Supplier} of {@code Spliterator.OfInt}.
   149      *
   145      *
   150      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
   146      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
   151      * more than once, and after the terminal operation of the stream pipeline
   147      * more than once, and only after the terminal operation of the stream pipeline
   152      * commences.
   148      * commences.
   153      *
   149      *
   154      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
   150      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
   155      * or {@code CONCURRENT}, or that are
   151      * or {@code CONCURRENT}, or that are
   156      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
   152      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
   157      * more efficient to use {@link #intStream(java.util.Spliterator.OfInt, boolean)}
   153      * more efficient to use {@link #intStream(java.util.Spliterator.OfInt, boolean)}
   158      * instead.
   154      * instead.
   159      * The use of a {@code Supplier} in this form provides a level of
   155      * <p>The use of a {@code Supplier} in this form provides a level of
   160      * indirection that reduces the scope of potential interference with the
   156      * indirection that reduces the scope of potential interference with the
   161      * source.  Since the supplier is only invoked after the terminal operation
   157      * source.  Since the supplier is only invoked after the terminal operation
   162      * commences, any modifications to the source up to the start of the
   158      * commences, any modifications to the source up to the start of the
   163      * terminal operation are reflected in the stream result.  See
   159      * terminal operation are reflected in the stream result.  See
   164      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
   160      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
   213     /**
   209     /**
   214      * Creates a new sequential or parallel {@code LongStream} from a
   210      * Creates a new sequential or parallel {@code LongStream} from a
   215      * {@code Supplier} of {@code Spliterator.OfLong}.
   211      * {@code Supplier} of {@code Spliterator.OfLong}.
   216      *
   212      *
   217      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
   213      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
   218      * more than once, and after the terminal operation of the stream pipeline
   214      * more than once, and only after the terminal operation of the stream pipeline
   219      * commences.
   215      * commences.
   220      *
   216      *
   221      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
   217      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
   222      * or {@code CONCURRENT}, or that are
   218      * or {@code CONCURRENT}, or that are
   223      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
   219      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
   224      * more efficient to use {@link #longStream(java.util.Spliterator.OfLong, boolean)}
   220      * more efficient to use {@link #longStream(java.util.Spliterator.OfLong, boolean)}
   225      * instead.
   221      * instead.
   226      * The use of a {@code Supplier} in this form provides a level of
   222      * <p>The use of a {@code Supplier} in this form provides a level of
   227      * indirection that reduces the scope of potential interference with the
   223      * indirection that reduces the scope of potential interference with the
   228      * source.  Since the supplier is only invoked after the terminal operation
   224      * source.  Since the supplier is only invoked after the terminal operation
   229      * commences, any modifications to the source up to the start of the
   225      * commences, any modifications to the source up to the start of the
   230      * terminal operation are reflected in the stream result.  See
   226      * terminal operation are reflected in the stream result.  See
   231      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
   227      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
   280     /**
   276     /**
   281      * Creates a new sequential or parallel {@code DoubleStream} from a
   277      * Creates a new sequential or parallel {@code DoubleStream} from a
   282      * {@code Supplier} of {@code Spliterator.OfDouble}.
   278      * {@code Supplier} of {@code Spliterator.OfDouble}.
   283      *
   279      *
   284      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
   280      * <p>The {@link Supplier#get()} method will be invoked on the supplier no
   285      * more than once, and after the terminal operation of the stream pipeline
   281      * more than once, and only after the terminal operation of the stream pipeline
   286      * commences.
   282      * commences.
   287      *
   283      *
   288      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
   284      * <p>For spliterators that report a characteristic of {@code IMMUTABLE}
   289      * or {@code CONCURRENT}, or that are
   285      * or {@code CONCURRENT}, or that are
   290      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
   286      * <a href="../Spliterator.html#binding">late-binding</a>, it is likely
   291      * more efficient to use {@link #doubleStream(java.util.Spliterator.OfDouble, boolean)}
   287      * more efficient to use {@link #doubleStream(java.util.Spliterator.OfDouble, boolean)}
   292      * instead.
   288      * instead.
   293      * The use of a {@code Supplier} in this form provides a level of
   289      * <p>The use of a {@code Supplier} in this form provides a level of
   294      * indirection that reduces the scope of potential interference with the
   290      * indirection that reduces the scope of potential interference with the
   295      * source.  Since the supplier is only invoked after the terminal operation
   291      * source.  Since the supplier is only invoked after the terminal operation
   296      * commences, any modifications to the source up to the start of the
   292      * commences, any modifications to the source up to the start of the
   297      * terminal operation are reflected in the stream result.  See
   293      * terminal operation are reflected in the stream result.  See
   298      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for
   294      * <a href="package-summary.html#Non-Interference">Non-Interference</a> for