jdk/src/share/classes/java/util/stream/DoubleStream.java
author psandoz
Mon, 25 Nov 2013 09:55:34 +0100
changeset 21846 c10feb34bc0b
parent 21339 20e8b81964d5
child 22352 ecbf37860ffa
permissions -rw-r--r--
8028516: Java doc error in Int/Long/Double/Stream.peek Reviewed-by: chegar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     1
/*
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     4
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    10
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    15
 * accompanied this code).
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    16
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    20
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    23
 * questions.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    24
 */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    25
package java.util.stream;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    26
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    27
import java.nio.charset.Charset;
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    28
import java.nio.file.Files;
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    29
import java.nio.file.Path;
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
    30
import java.util.Arrays;
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    31
import java.util.Collection;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    32
import java.util.DoubleSummaryStatistics;
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
    33
import java.util.Objects;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    34
import java.util.OptionalDouble;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    35
import java.util.PrimitiveIterator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    36
import java.util.Spliterator;
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
    37
import java.util.Spliterators;
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    38
import java.util.concurrent.ConcurrentHashMap;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    39
import java.util.function.BiConsumer;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    40
import java.util.function.DoubleBinaryOperator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    41
import java.util.function.DoubleConsumer;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    42
import java.util.function.DoubleFunction;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    43
import java.util.function.DoublePredicate;
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
    44
import java.util.function.DoubleSupplier;
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    45
import java.util.function.DoubleToIntFunction;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    46
import java.util.function.DoubleToLongFunction;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    47
import java.util.function.DoubleUnaryOperator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    48
import java.util.function.Function;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    49
import java.util.function.ObjDoubleConsumer;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    50
import java.util.function.Supplier;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    51
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    52
/**
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    53
 * A sequence of primitive double-valued elements supporting sequential and parallel
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    54
 * aggregate operations.  This is the {@code double} primitive specialization of
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    55
 * {@link Stream}.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    56
 *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    57
 * <p>The following example illustrates an aggregate operation using
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    58
 * {@link Stream} and {@link DoubleStream}, computing the sum of the weights of the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    59
 * red widgets:
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    60
 *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    61
 * <pre>{@code
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    62
 *     double sum = widgets.stream()
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    63
 *                         .filter(w -> w.getColor() == RED)
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    64
 *                         .mapToDouble(w -> w.getWeight())
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    65
 *                         .sum();
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    66
 * }</pre>
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
    67
 *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    68
 * See the class documentation for {@link Stream} and the package documentation
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    69
 * for <a href="package-summary.html">java.util.stream</a> for additional
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    70
 * specification of streams, stream operations, stream pipelines, and
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    71
 * parallelism.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    72
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    73
 * @since 1.8
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    74
 * @see Stream
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    75
 * @see <a href="package-summary.html">java.util.stream</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    76
 */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    77
public interface DoubleStream extends BaseStream<Double, DoubleStream> {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    78
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    79
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    80
     * Returns a stream consisting of the elements of this stream that match
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    81
     * the given predicate.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    82
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    83
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    84
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    85
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    86
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    87
     *                  <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    88
     *                  predicate to apply to each element to determine if it
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
    89
     *                  should be included
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    90
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    91
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    92
    DoubleStream filter(DoublePredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    93
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    94
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    95
     * Returns a stream consisting of the results of applying the given
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    96
     * function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    97
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    98
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    99
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   100
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   101
     * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   102
     *               <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   103
     *               function to apply to each element
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   104
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   105
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   106
    DoubleStream map(DoubleUnaryOperator mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   107
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   108
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   109
     * Returns an object-valued {@code Stream} consisting of the results of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   110
     * applying the given function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   111
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   112
     * <p>This is an <a href="package-summary.html#StreamOps">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   113
     *     intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   114
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   115
     * @param <U> the element type of the new stream
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   116
     * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   117
     *               <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   118
     *               function to apply to each element
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   119
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   120
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   121
    <U> Stream<U> mapToObj(DoubleFunction<? extends U> mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   122
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   123
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   124
     * Returns an {@code IntStream} consisting of the results of applying the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   125
     * given function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   126
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   127
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   128
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   129
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   130
     * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   131
     *               <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   132
     *               function to apply to each element
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   133
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   134
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   135
    IntStream mapToInt(DoubleToIntFunction mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   136
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   137
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   138
     * Returns a {@code LongStream} consisting of the results of applying the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   139
     * given function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   140
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   141
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   142
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   143
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   144
     * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   145
     *               <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   146
     *               function to apply to each element
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   147
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   148
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   149
    LongStream mapToLong(DoubleToLongFunction mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   150
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   151
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   152
     * Returns a stream consisting of the results of replacing each element of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   153
     * this stream with the contents of the stream produced by applying the
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   154
     * provided mapping function to each element.  (If the result of the mapping
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   155
     * function is {@code null}, this is treated as if the result was an empty
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   156
     * stream.)
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   157
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   158
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   159
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   160
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   161
     * @param mapper a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   162
     *               <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   163
     *               function to apply to each element which produces a
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   164
     *               {@code DoubleStream} of new values
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   165
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   166
     * @see Stream#flatMap(Function)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   167
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   168
    DoubleStream flatMap(DoubleFunction<? extends DoubleStream> mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   169
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   170
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   171
     * Returns a stream consisting of the distinct elements of this stream. The
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   172
     * elements are compared for equality according to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   173
     * {@link java.lang.Double#compare(double, double)}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   174
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   175
     * <p>This is a <a href="package-summary.html#StreamOps">stateful
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   176
     * intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   177
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   178
     * @return the result stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   179
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   180
    DoubleStream distinct();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   181
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   182
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   183
     * Returns a stream consisting of the elements of this stream in sorted
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   184
     * order. The elements are compared for equality according to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   185
     * {@link java.lang.Double#compare(double, double)}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   186
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   187
     * <p>This is a <a href="package-summary.html#StreamOps">stateful
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   188
     * intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   189
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   190
     * @return the result stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   191
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   192
    DoubleStream sorted();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   193
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   194
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   195
     * Returns a stream consisting of the elements of this stream, additionally
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   196
     * performing the provided action on each element as elements are consumed
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   197
     * from the resulting stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   198
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   199
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   200
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   201
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   202
     * <p>For parallel stream pipelines, the action may be called at
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   203
     * whatever time and in whatever thread the element is made available by the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   204
     * upstream operation.  If the action modifies shared state,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   205
     * it is responsible for providing the required synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   206
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   207
     * @apiNote This method exists mainly to support debugging, where you want
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   208
     * to see the elements as they flow past a certain point in a pipeline:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   209
     * <pre>{@code
21846
c10feb34bc0b 8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents: 21339
diff changeset
   210
     *     DoubleStream.of(1, 2, 3, 4)
c10feb34bc0b 8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents: 21339
diff changeset
   211
     *         .filter(e -> e > 2)
c10feb34bc0b 8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents: 21339
diff changeset
   212
     *         .peek(e -> System.out.println("Filtered value: " + e))
c10feb34bc0b 8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents: 21339
diff changeset
   213
     *         .map(e -> e * e)
c10feb34bc0b 8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents: 21339
diff changeset
   214
     *         .peek(e -> System.out.println("Mapped value: " + e))
c10feb34bc0b 8028516: Java doc error in Int/Long/Double/Stream.peek
psandoz
parents: 21339
diff changeset
   215
     *         .sum();
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   216
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   217
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   218
     * @param action a <a href="package-summary.html#NonInterference">
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   219
     *               non-interfering</a> action to perform on the elements as
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   220
     *               they are consumed from the stream
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   221
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   222
     */
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   223
    DoubleStream peek(DoubleConsumer action);
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   224
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   225
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   226
     * Returns a stream consisting of the elements of this stream, truncated
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   227
     * to be no longer than {@code maxSize} in length.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   228
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   229
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   230
     * stateful intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   231
     *
20866
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   232
     * @apiNote
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   233
     * While {@code limit()} is generally a cheap operation on sequential
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   234
     * stream pipelines, it can be quite expensive on ordered parallel pipelines,
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   235
     * especially for large values of {@code maxSize}, since {@code limit(n)}
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   236
     * is constrained to return not just any <em>n</em> elements, but the
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   237
     * <em>first n</em> elements in the encounter order.  Using an unordered
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   238
     * stream source (such as {@link #generate(DoubleSupplier)}) or removing the
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   239
     * ordering constraint with {@link #unordered()} may result in significant
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   240
     * speedups of {@code limit()} in parallel pipelines, if the semantics of
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   241
     * your situation permit.  If consistency with encounter order is required,
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   242
     * and you are experiencing poor performance or memory utilization with
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   243
     * {@code limit()} in parallel pipelines, switching to sequential execution
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   244
     * with {@link #sequential()} may improve performance.
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   245
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   246
     * @param maxSize the number of elements the stream should be limited to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   247
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   248
     * @throws IllegalArgumentException if {@code maxSize} is negative
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   249
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   250
    DoubleStream limit(long maxSize);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   251
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   252
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   253
     * Returns a stream consisting of the remaining elements of this stream
20866
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   254
     * after discarding the first {@code n} elements of the stream.
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   255
     * If this stream contains fewer than {@code n} elements then an
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   256
     * empty stream will be returned.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   257
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   258
     * <p>This is a <a href="package-summary.html#StreamOps">stateful
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   259
     * intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   260
     *
20866
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   261
     * @apiNote
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   262
     * While {@code skip()} is generally a cheap operation on sequential
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   263
     * stream pipelines, it can be quite expensive on ordered parallel pipelines,
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   264
     * especially for large values of {@code n}, since {@code skip(n)}
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   265
     * is constrained to skip not just any <em>n</em> elements, but the
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   266
     * <em>first n</em> elements in the encounter order.  Using an unordered
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   267
     * stream source (such as {@link #generate(DoubleSupplier)}) or removing the
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   268
     * ordering constraint with {@link #unordered()} may result in significant
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   269
     * speedups of {@code skip()} in parallel pipelines, if the semantics of
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   270
     * your situation permit.  If consistency with encounter order is required,
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   271
     * and you are experiencing poor performance or memory utilization with
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   272
     * {@code skip()} in parallel pipelines, switching to sequential execution
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   273
     * with {@link #sequential()} may improve performance.
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   274
     *
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   275
     * @param n the number of leading elements to skip
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   276
     * @return the new stream
20866
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   277
     * @throws IllegalArgumentException if {@code n} is negative
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   278
     */
20866
36155ee613ef 8025910: rename substream(long) -> skip and remove substream(long,long)
mduigou
parents: 20758
diff changeset
   279
    DoubleStream skip(long n);
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   280
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   281
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   282
     * Performs an action for each element of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   283
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   284
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   285
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   286
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   287
     * <p>For parallel stream pipelines, this operation does <em>not</em>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   288
     * guarantee to respect the encounter order of the stream, as doing so
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   289
     * would sacrifice the benefit of parallelism.  For any given element, the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   290
     * action may be performed at whatever time and in whatever thread the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   291
     * library chooses.  If the action accesses shared state, it is
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   292
     * responsible for providing the required synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   293
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   294
     * @param action a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   295
     *               non-interfering</a> action to perform on the elements
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   296
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   297
    void forEach(DoubleConsumer action);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   298
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   299
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   300
     * Performs an action for each element of this stream, guaranteeing that
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   301
     * each element is processed in encounter order for streams that have a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   302
     * defined encounter order.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   303
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   304
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   305
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   306
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   307
     * @param action a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   308
     *               non-interfering</a> action to perform on the elements
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   309
     * @see #forEach(DoubleConsumer)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   310
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   311
    void forEachOrdered(DoubleConsumer action);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   312
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   313
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   314
     * Returns an array containing the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   315
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   316
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   317
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   318
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   319
     * @return an array containing the elements of this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   320
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   321
    double[] toArray();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   322
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   323
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   324
     * Performs a <a href="package-summary.html#Reduction">reduction</a> on the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   325
     * elements of this stream, using the provided identity value and an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   326
     * <a href="package-summary.html#Associativity">associative</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   327
     * accumulation function, and returns the reduced value.  This is equivalent
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   328
     * to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   329
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   330
     *     double result = identity;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   331
     *     for (double element : this stream)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   332
     *         result = accumulator.apply(result, element)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   333
     *     return result;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   334
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   335
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   336
     * but is not constrained to execute sequentially.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   337
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   338
     * <p>The {@code identity} value must be an identity for the accumulator
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   339
     * function. This means that for all {@code x},
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   340
     * {@code accumulator.apply(identity, x)} is equal to {@code x}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   341
     * The {@code accumulator} function must be an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   342
     * <a href="package-summary.html#Associativity">associative</a> function.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   343
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   344
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   345
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   346
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   347
     * @apiNote Sum, min, max, and average are all special cases of reduction.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   348
     * Summing a stream of numbers can be expressed as:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   349
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   350
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   351
     *     double sum = numbers.reduce(0, (a, b) -> a+b);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   352
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   353
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   354
     * or more compactly:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   355
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   356
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   357
     *     double sum = numbers.reduce(0, Double::sum);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   358
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   359
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   360
     * <p>While this may seem a more roundabout way to perform an aggregation
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   361
     * compared to simply mutating a running total in a loop, reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   362
     * operations parallelize more gracefully, without needing additional
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   363
     * synchronization and with greatly reduced risk of data races.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   364
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   365
     * @param identity the identity value for the accumulating function
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   366
     * @param op an <a href="package-summary.html#Associativity">associative</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   367
     *           <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   368
     *           <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   369
     *           function for combining two values
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   370
     * @return the result of the reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   371
     * @see #sum()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   372
     * @see #min()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   373
     * @see #max()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   374
     * @see #average()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   375
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   376
    double reduce(double identity, DoubleBinaryOperator op);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   377
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   378
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   379
     * Performs a <a href="package-summary.html#Reduction">reduction</a> on the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   380
     * elements of this stream, using an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   381
     * <a href="package-summary.html#Associativity">associative</a> accumulation
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   382
     * function, and returns an {@code OptionalDouble} describing the reduced
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   383
     * value, if any. This is equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   384
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   385
     *     boolean foundAny = false;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   386
     *     double result = null;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   387
     *     for (double element : this stream) {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   388
     *         if (!foundAny) {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   389
     *             foundAny = true;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   390
     *             result = element;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   391
     *         }
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   392
     *         else
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   393
     *             result = accumulator.apply(result, element);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   394
     *     }
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   395
     *     return foundAny ? OptionalDouble.of(result) : OptionalDouble.empty();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   396
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   397
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   398
     * but is not constrained to execute sequentially.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   399
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   400
     * <p>The {@code accumulator} function must be an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   401
     * <a href="package-summary.html#Associativity">associative</a> function.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   402
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   403
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   404
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   405
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   406
     * @param op an <a href="package-summary.html#Associativity">associative</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   407
     *           <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   408
     *           <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   409
     *           function for combining two values
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   410
     * @return the result of the reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   411
     * @see #reduce(double, DoubleBinaryOperator)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   412
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   413
    OptionalDouble reduce(DoubleBinaryOperator op);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   414
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   415
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   416
     * Performs a <a href="package-summary.html#MutableReduction">mutable
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   417
     * reduction</a> operation on the elements of this stream.  A mutable
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   418
     * reduction is one in which the reduced value is a mutable result container,
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   419
     * such as an {@code ArrayList}, and elements are incorporated by updating
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   420
     * the state of the result rather than by replacing the result.  This
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   421
     * produces a result equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   422
     * <pre>{@code
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   423
     *     R result = supplier.get();
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   424
     *     for (double element : this stream)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   425
     *         accumulator.accept(result, element);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   426
     *     return result;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   427
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   428
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   429
     * <p>Like {@link #reduce(double, DoubleBinaryOperator)}, {@code collect}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   430
     * operations can be parallelized without requiring additional
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   431
     * synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   432
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   433
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   434
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   435
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   436
     * @param <R> type of the result
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   437
     * @param supplier a function that creates a new result container. For a
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   438
     *                 parallel execution, this function may be called
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   439
     *                 multiple times and must return a fresh value each time.
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   440
     * @param accumulator an <a href="package-summary.html#Associativity">associative</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   441
     *                    <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   442
     *                    <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   443
     *                    function for incorporating an additional element into a result
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   444
     * @param combiner an <a href="package-summary.html#Associativity">associative</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   445
     *                    <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   446
     *                    <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   447
     *                    function for combining two values, which must be
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   448
     *                    compatible with the accumulator function
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   449
     * @return the result of the reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   450
     * @see Stream#collect(Supplier, BiConsumer, BiConsumer)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   451
     */
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   452
    <R> R collect(Supplier<R> supplier,
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   453
                  ObjDoubleConsumer<R> accumulator,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   454
                  BiConsumer<R, R> combiner);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   455
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   456
    /**
20758
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   457
     * Returns the sum of elements in this stream.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   458
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   459
     * Summation is a special case of a <a
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   460
     * href="package-summary.html#Reduction">reduction</a>. If
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   461
     * floating-point summation were exact, this method would be
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   462
     * equivalent to:
20758
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   463
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   464
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   465
     *     return reduce(0, Double::sum);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   466
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   467
     *
20758
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   468
     * However, since floating-point summation is not exact, the above
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   469
     * code is not necessarily equivalent to the summation computation
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   470
     * done by this method.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   471
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   472
     * <p>If any stream element is a NaN or the sum is at any point a NaN
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   473
     * then the sum will be NaN.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   474
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   475
     * The value of a floating-point sum is a function both
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   476
     * of the input values as well as the order of addition
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   477
     * operations. The order of addition operations of this method is
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   478
     * intentionally not defined to allow for implementation
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   479
     * flexibility to improve the speed and accuracy of the computed
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   480
     * result.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   481
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   482
     * In particular, this method may be implemented using compensated
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   483
     * summation or other technique to reduce the error bound in the
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   484
     * numerical sum compared to a simple summation of {@code double}
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   485
     * values.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   486
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   487
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   488
     * operation</a>.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   489
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   490
     * @apiNote Elements sorted by increasing absolute magnitude tend
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   491
     * to yield more accurate results.
20758
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   492
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   493
     * @return the sum of elements in this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   494
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   495
    double sum();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   496
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   497
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   498
     * Returns an {@code OptionalDouble} describing the minimum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   499
     * stream, or an empty OptionalDouble if this stream is empty.  The minimum
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   500
     * element will be {@code Double.NaN} if any stream element was NaN. Unlike
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   501
     * the numerical comparison operators, this method considers negative zero
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   502
     * to be strictly smaller than positive zero. This is a special case of a
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   503
     * <a href="package-summary.html#Reduction">reduction</a> and is
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   504
     * equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   505
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   506
     *     return reduce(Double::min);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   507
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   508
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   509
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   510
     * operation</a>.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   511
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   512
     * @return an {@code OptionalDouble} containing the minimum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   513
     * stream, or an empty optional if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   514
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   515
    OptionalDouble min();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   516
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   517
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   518
     * Returns an {@code OptionalDouble} describing the maximum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   519
     * stream, or an empty OptionalDouble if this stream is empty.  The maximum
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   520
     * element will be {@code Double.NaN} if any stream element was NaN. Unlike
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   521
     * the numerical comparison operators, this method considers negative zero
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   522
     * to be strictly smaller than positive zero. This is a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   523
     * special case of a
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   524
     * <a href="package-summary.html#Reduction">reduction</a> and is
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   525
     * equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   526
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   527
     *     return reduce(Double::max);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   528
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   529
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   530
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   531
     * operation</a>.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   532
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   533
     * @return an {@code OptionalDouble} containing the maximum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   534
     * stream, or an empty optional if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   535
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   536
    OptionalDouble max();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   537
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   538
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   539
     * Returns the count of elements in this stream.  This is a special case of
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   540
     * a <a href="package-summary.html#Reduction">reduction</a> and is
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   541
     * equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   542
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   543
     *     return mapToLong(e -> 1L).sum();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   544
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   545
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   546
     * <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   547
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   548
     * @return the count of elements in this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   549
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   550
    long count();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   551
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   552
    /**
20758
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   553
     * Returns an {@code OptionalDouble} describing the arithmetic
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   554
     * mean of elements of this stream, or an empty optional if this
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   555
     * stream is empty.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   556
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   557
     * If any recorded value is a NaN or the sum is at any point a NaN
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   558
     * then the average will be NaN.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   559
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   560
     * <p>The average returned can vary depending upon the order in
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   561
     * which values are recorded.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   562
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   563
     * This method may be implemented using compensated summation or
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   564
     * other technique to reduce the error bound in the {@link #sum
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   565
     * numerical sum} used to compute the average.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   566
     *
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   567
     *  <p>The average is a special case of a <a
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   568
     *  href="package-summary.html#Reduction">reduction</a>.
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   569
     *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   570
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   571
     * operation</a>.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   572
     *
20758
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   573
     * @apiNote Elements sorted by increasing absolute magnitude tend
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   574
     * to yield more accurate results.
d8845d3fb428 8024354: Explicitly permit DoubleStream.sum()/average() implementations to use higher precision summation
darcy
parents: 19850
diff changeset
   575
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   576
     * @return an {@code OptionalDouble} containing the average element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   577
     * stream, or an empty optional if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   578
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   579
    OptionalDouble average();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   580
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   581
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   582
     * Returns a {@code DoubleSummaryStatistics} describing various summary data
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   583
     * about the elements of this stream.  This is a special
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   584
     * case of a <a href="package-summary.html#Reduction">reduction</a>.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   585
     *
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   586
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   587
     * operation</a>.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   588
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   589
     * @return a {@code DoubleSummaryStatistics} describing various summary data
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   590
     * about the elements of this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   591
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   592
    DoubleSummaryStatistics summaryStatistics();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   593
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   594
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   595
     * Returns whether any elements of this stream match the provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   596
     * predicate.  May not evaluate the predicate on all elements if not
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   597
     * necessary for determining the result.  If the stream is empty then
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   598
     * {@code false} is returned and the predicate is not evaluated.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   599
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   600
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   601
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   602
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   603
     * @apiNote
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   604
     * This method evaluates the <em>existential quantification</em> of the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   605
     * predicate over the elements of the stream (for some x P(x)).
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   606
     *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   607
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   608
     *                  <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   609
     *                  predicate to apply to elements of this stream
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   610
     * @return {@code true} if any elements of the stream match the provided
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   611
     * predicate, otherwise {@code false}
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   612
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   613
    boolean anyMatch(DoublePredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   614
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   615
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   616
     * Returns whether all elements of this stream match the provided predicate.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   617
     * May not evaluate the predicate on all elements if not necessary for
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   618
     * determining the result.  If the stream is empty then {@code true} is
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   619
     * returned and the predicate is not evaluated.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   620
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   621
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   622
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   623
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   624
     * @apiNote
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   625
     * This method evaluates the <em>universal quantification</em> of the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   626
     * predicate over the elements of the stream (for all x P(x)).  If the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   627
     * stream is empty, the quantification is said to be <em>vacuously
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   628
     * satisfied</em> and is always {@code true} (regardless of P(x)).
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   629
     *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   630
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   631
     *                  <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   632
     *                  predicate to apply to elements of this stream
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   633
     * @return {@code true} if either all elements of the stream match the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   634
     * provided predicate or the stream is empty, otherwise {@code false}
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   635
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   636
    boolean allMatch(DoublePredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   637
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   638
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   639
     * Returns whether no elements of this stream match the provided predicate.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   640
     * May not evaluate the predicate on all elements if not necessary for
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   641
     * determining the result.  If the stream is empty then {@code true} is
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   642
     * returned and the predicate is not evaluated.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   643
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   644
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   645
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   646
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   647
     * @apiNote
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   648
     * This method evaluates the <em>universal quantification</em> of the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   649
     * negated predicate over the elements of the stream (for all x ~P(x)).  If
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   650
     * the stream is empty, the quantification is said to be vacuously satisfied
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   651
     * and is always {@code true}, regardless of P(x).
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   652
     *
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   653
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering</a>,
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   654
     *                  <a href="package-summary.html#Statelessness">stateless</a>
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   655
     *                  predicate to apply to elements of this stream
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   656
     * @return {@code true} if either no elements of the stream match the
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   657
     * provided predicate or the stream is empty, otherwise {@code false}
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   658
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   659
    boolean noneMatch(DoublePredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   660
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   661
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   662
     * Returns an {@link OptionalDouble} describing the first element of this
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   663
     * stream, or an empty {@code OptionalDouble} if the stream is empty.  If
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   664
     * the stream has no encounter order, then any element may be returned.
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   665
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   666
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   667
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   668
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   669
     * @return an {@code OptionalDouble} describing the first element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   670
     * stream, or an empty {@code OptionalDouble} if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   671
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   672
    OptionalDouble findFirst();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   673
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   674
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   675
     * Returns an {@link OptionalDouble} describing some element of the stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   676
     * or an empty {@code OptionalDouble} if the stream is empty.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   677
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   678
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   679
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   680
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   681
     * <p>The behavior of this operation is explicitly nondeterministic; it is
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   682
     * free to select any element in the stream.  This is to allow for maximal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   683
     * performance in parallel operations; the cost is that multiple invocations
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   684
     * on the same source may not return the same result.  (If a stable result
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   685
     * is desired, use {@link #findFirst()} instead.)
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   686
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   687
     * @return an {@code OptionalDouble} describing some element of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   688
     * or an empty {@code OptionalDouble} if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   689
     * @see #findFirst()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   690
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   691
    OptionalDouble findAny();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   692
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   693
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   694
     * Returns a {@code Stream} consisting of the elements of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   695
     * boxed to {@code Double}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   696
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   697
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   698
     * operation</a>.
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   699
     *
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   700
     * @return a {@code Stream} consistent of the elements of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   701
     * each boxed to a {@code Double}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   702
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   703
    Stream<Double> boxed();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   704
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   705
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   706
    DoubleStream sequential();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   707
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   708
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   709
    DoubleStream parallel();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   710
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   711
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   712
    PrimitiveIterator.OfDouble iterator();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   713
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   714
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   715
    Spliterator.OfDouble spliterator();
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   716
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   717
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   718
    // Static factories
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   719
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   720
    /**
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   721
     * Returns a builder for a {@code DoubleStream}.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   722
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   723
     * @return a stream builder
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   724
     */
18825
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   725
    public static Builder builder() {
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   726
        return new Streams.DoubleStreamBuilderImpl();
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   727
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   728
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   729
    /**
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   730
     * Returns an empty sequential {@code DoubleStream}.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   731
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   732
     * @return an empty sequential stream
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   733
     */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   734
    public static DoubleStream empty() {
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 18820
diff changeset
   735
        return StreamSupport.doubleStream(Spliterators.emptyDoubleSpliterator(), false);
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   736
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   737
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   738
    /**
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   739
     * Returns a sequential {@code DoubleStream} containing a single element.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   740
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   741
     * @param t the single element
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   742
     * @return a singleton sequential stream
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   743
     */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   744
    public static DoubleStream of(double t) {
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 18820
diff changeset
   745
        return StreamSupport.doubleStream(new Streams.DoubleStreamBuilderImpl(t), false);
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   746
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   747
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   748
    /**
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   749
     * Returns a sequential ordered stream whose elements are the specified values.
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   750
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   751
     * @param values the elements of the new stream
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   752
     * @return the new stream
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   753
     */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   754
    public static DoubleStream of(double... values) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   755
        return Arrays.stream(values);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   756
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   757
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   758
    /**
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   759
     * Returns an infinite sequential ordered {@code DoubleStream} produced by iterative
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   760
     * application of a function {@code f} to an initial element {@code seed},
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   761
     * producing a {@code Stream} consisting of {@code seed}, {@code f(seed)},
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   762
     * {@code f(f(seed))}, etc.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   763
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   764
     * <p>The first element (position {@code 0}) in the {@code DoubleStream}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   765
     * will be the provided {@code seed}.  For {@code n > 0}, the element at
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   766
     * position {@code n}, will be the result of applying the function {@code f}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   767
     *  to the element at position {@code n - 1}.
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   768
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   769
     * @param seed the initial element
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   770
     * @param f a function to be applied to to the previous element to produce
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   771
     *          a new element
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   772
     * @return a new sequential {@code DoubleStream}
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   773
     */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   774
    public static DoubleStream iterate(final double seed, final DoubleUnaryOperator f) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   775
        Objects.requireNonNull(f);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   776
        final PrimitiveIterator.OfDouble iterator = new PrimitiveIterator.OfDouble() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   777
            double t = seed;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   778
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   779
            @Override
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   780
            public boolean hasNext() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   781
                return true;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   782
            }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   783
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   784
            @Override
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   785
            public double nextDouble() {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   786
                double v = t;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   787
                t = f.applyAsDouble(t);
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   788
                return v;
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   789
            }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   790
        };
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   791
        return StreamSupport.doubleStream(Spliterators.spliteratorUnknownSize(
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   792
                iterator,
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 18820
diff changeset
   793
                Spliterator.ORDERED | Spliterator.IMMUTABLE | Spliterator.NONNULL), false);
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   794
    }
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   795
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   796
    /**
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   797
     * Returns an infinite sequential unordered stream where each element is
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   798
     * generated by the provided {@code DoubleSupplier}.  This is suitable for
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   799
     * generating constant streams, streams of random elements, etc.
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   800
     *
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   801
     * @param s the {@code DoubleSupplier} for generated elements
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   802
     * @return a new infinite sequential unordered {@code DoubleStream}
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   803
     */
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   804
    public static DoubleStream generate(DoubleSupplier s) {
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   805
        Objects.requireNonNull(s);
18572
53b8b8c30086 8012987: Optimizations for Stream.limit/substream
psandoz
parents: 18153
diff changeset
   806
        return StreamSupport.doubleStream(
18822
4b6be7c19547 8019395: Consolidate StreamSupport.{stream,parallelStream} into a single method
psandoz
parents: 18820
diff changeset
   807
                new StreamSpliterators.InfiniteSupplyingSpliterator.OfDouble(Long.MAX_VALUE, s), false);
17195
e897ad52979e 8012650: Arrays streams methods
briangoetz
parents: 17167
diff changeset
   808
    }
18820
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   809
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   810
    /**
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   811
     * Creates a lazily concatenated stream whose elements are all the
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   812
     * elements of the first stream followed by all the elements of the
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   813
     * second stream.  The resulting stream is ordered if both
18820
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   814
     * of the input streams are ordered, and parallel if either of the input
19800
6e1fef53ea55 8017513: Support for closeable streams
henryjen
parents: 19214
diff changeset
   815
     * streams is parallel.  When the resulting stream is closed, the close
6e1fef53ea55 8017513: Support for closeable streams
henryjen
parents: 19214
diff changeset
   816
     * handlers for both input streams are invoked.
18820
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   817
     *
21339
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   818
     * @implNote
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   819
     * Use caution when constructing streams from repeated concatenation.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   820
     * Accessing an element of a deeply concatenated stream can result in deep
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   821
     * call chains, or even {@code StackOverflowException}.
20e8b81964d5 8025909: Lambda Library Spec Updates
henryjen
parents: 20866
diff changeset
   822
     *
18820
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   823
     * @param a the first stream
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   824
     * @param b the second stream
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   825
     * @return the concatenation of the two input streams
18820
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   826
     */
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   827
    public static DoubleStream concat(DoubleStream a, DoubleStream b) {
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   828
        Objects.requireNonNull(a);
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   829
        Objects.requireNonNull(b);
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   830
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   831
        Spliterator.OfDouble split = new Streams.ConcatSpliterator.OfDouble(
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   832
                a.spliterator(), b.spliterator());
19800
6e1fef53ea55 8017513: Support for closeable streams
henryjen
parents: 19214
diff changeset
   833
        DoubleStream stream = StreamSupport.doubleStream(split, a.isParallel() || b.isParallel());
6e1fef53ea55 8017513: Support for closeable streams
henryjen
parents: 19214
diff changeset
   834
        return stream.onClose(Streams.composedClose(a, b));
18820
a87cdd6a8834 8015315: Stream.concat methods
mduigou
parents: 18572
diff changeset
   835
    }
18825
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   836
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   837
    /**
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   838
     * A mutable builder for a {@code DoubleStream}.
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   839
     *
19850
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   840
     * <p>A stream builder has a lifecycle, which starts in a building
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   841
     * phase, during which elements can be added, and then transitions to a built
93b368e54c1c 8011916: Spec update for java.util.stream
henryjen
parents: 19800
diff changeset
   842
     * phase, after which elements may not be added.  The built phase
18825
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   843
     * begins when the {@link #build()} method is called, which creates an
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   844
     * ordered stream whose elements are the elements that were added to the
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   845
     * stream builder, in the order they were added.
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   846
     *
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   847
     * @see DoubleStream#builder()
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   848
     * @since 1.8
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   849
     */
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   850
    public interface Builder extends DoubleConsumer {
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   851
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   852
        /**
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   853
         * Adds an element to the stream being built.
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   854
         *
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   855
         * @throws IllegalStateException if the builder has already transitioned
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   856
         * to the built state
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   857
         */
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   858
        @Override
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   859
        void accept(double t);
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   860
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   861
        /**
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   862
         * Adds an element to the stream being built.
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   863
         *
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   864
         * @implSpec
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   865
         * The default implementation behaves as if:
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   866
         * <pre>{@code
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   867
         *     accept(t)
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   868
         *     return this;
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   869
         * }</pre>
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   870
         *
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   871
         * @param t the element to add
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   872
         * @return {@code this} builder
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   873
         * @throws IllegalStateException if the builder has already transitioned
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   874
         * to the built state
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   875
         */
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   876
        default Builder add(double t) {
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   877
            accept(t);
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   878
            return this;
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   879
        }
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   880
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   881
        /**
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   882
         * Builds the stream, transitioning this builder to the built state.
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   883
         * An {@code IllegalStateException} is thrown if there are further
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   884
         * attempts to operate on the builder after it has entered the built
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   885
         * state.
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   886
         *
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   887
         * @return the built stream
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   888
         * @throws IllegalStateException if the builder has already transitioned
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   889
         * to the built state
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   890
         */
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   891
        DoubleStream build();
06636235cd12 8020062: Nest StreamBuilder interfaces inside relevant Stream interfaces
henryjen
parents: 18822
diff changeset
   892
    }
17167
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   893
}