jdk/src/share/classes/java/util/stream/LongStream.java
author briangoetz
Wed, 17 Apr 2013 14:39:04 -0400
changeset 17167 87067e3340d3
child 17195 e897ad52979e
permissions -rw-r--r--
8008682: Inital Streams public API Reviewed-by: mduigou, dholmes, darcy Contributed-by: Brian Goetz <brian.goetz@oracle.com>, Mike Duigou <mike.duigou@oracle.com>, Paul Sandoz <paul.sandoz@oracle.com>, JSR-335 EG <lambda-libs-spec-experts@openjdk.java.net>
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) 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
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    27
import java.util.LongSummaryStatistics;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    28
import java.util.OptionalDouble;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    29
import java.util.OptionalLong;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    30
import java.util.PrimitiveIterator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    31
import java.util.Spliterator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    32
import java.util.function.BiConsumer;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    33
import java.util.function.Function;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    34
import java.util.function.LongBinaryOperator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    35
import java.util.function.LongConsumer;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    36
import java.util.function.LongFunction;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    37
import java.util.function.LongPredicate;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    38
import java.util.function.LongToDoubleFunction;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    39
import java.util.function.LongToIntFunction;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    40
import java.util.function.LongUnaryOperator;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    41
import java.util.function.ObjLongConsumer;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    42
import java.util.function.Supplier;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    43
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    44
/**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    45
 * A sequence of primitive long elements supporting sequential and parallel
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    46
 * bulk operations. Streams support lazy intermediate operations (transforming
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    47
 * a stream to another stream) such as {@code filter} and {@code map}, and terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    48
 * operations (consuming the contents of a stream to produce a result or
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    49
 * side-effect), such as {@code forEach}, {@code findFirst}, and {@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    50
 * iterator}.  Once an operation has been performed on a stream, it
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    51
 * is considered <em>consumed</em> and no longer usable for other operations.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    52
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    53
 * <p>For sequential stream pipelines, all operations are performed in the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    54
 * <a href="package-summary.html#Ordering">encounter order</a> of the pipeline
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    55
 * source, if the pipeline source has a defined encounter order.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    56
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    57
 * <p>For parallel stream pipelines, unless otherwise specified, intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    58
 * stream operations preserve the <a href="package-summary.html#Ordering">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    59
 * encounter order</a> of their source, and terminal operations
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    60
 * respect the encounter order of their source, if the source
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    61
 * has an encounter order.  Provided that and parameters to stream operations
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    62
 * satisfy the <a href="package-summary.html#NonInterference">non-interference
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    63
 * requirements</a>, and excepting differences arising from the absence of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    64
 * a defined encounter order, the result of a stream pipeline should be the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    65
 * stable across multiple executions of the same operations on the same source.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    66
 * However, the timing and thread in which side-effects occur (for those
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    67
 * operations which are allowed to produce side-effects, such as
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    68
 * {@link #forEach(LongConsumer)}), are explicitly nondeterministic for parallel
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    69
 * execution of stream pipelines.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    70
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    71
 * <p>Unless otherwise noted, passing a {@code null} argument to any stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    72
 * method may result in a {@link NullPointerException}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    73
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    74
 * @apiNote
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    75
 * Streams are not data structures; they do not manage the storage for their
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    76
 * elements, nor do they support access to individual elements.  However,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    77
 * you can use the {@link #iterator()} or {@link #spliterator()} operations to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    78
 * perform a controlled traversal.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    79
 *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    80
 * @since 1.8
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    81
 * @see <a href="package-summary.html">java.util.stream</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    82
 */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    83
public interface LongStream extends BaseStream<Long, LongStream> {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    84
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    85
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    86
     * Returns a stream consisting of the elements of this stream that match
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    87
     * the given predicate.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    88
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    89
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    90
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    91
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    92
     * @param predicate a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    93
     *                  non-interfering, stateless</a> predicate to apply to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    94
     *                  each element to determine if it should be included
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    95
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    96
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    97
    LongStream filter(LongPredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    98
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
    99
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   100
     * Returns a stream consisting of the results of applying the given
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   101
     * function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   102
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   103
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   104
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   105
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   106
     * @param mapper a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   107
     *               non-interfering, stateless</a> function to apply to each
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   108
     *               element
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   109
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   110
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   111
    LongStream map(LongUnaryOperator mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   112
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   113
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   114
     * Returns an object-valued {@code Stream} consisting of the results of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   115
     * applying the given function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   116
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   117
     * <p>This is an <a href="package-summary.html#StreamOps">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   118
     *     intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   119
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   120
     * @param <U> the element type of the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   121
     * @param mapper a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   122
     *               non-interfering, stateless</a> function to apply to each
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   123
     *               element
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   124
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   125
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   126
    <U> Stream<U> mapToObj(LongFunction<? extends U> mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   127
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   128
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   129
     * Returns an {@code IntStream} consisting of the results of applying the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   130
     * given function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   131
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   132
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   133
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   134
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   135
     * @param mapper a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   136
     *               non-interfering, stateless</a> function to apply to each
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   137
     *               element
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   138
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   139
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   140
    IntStream mapToInt(LongToIntFunction mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   141
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   142
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   143
     * Returns a {@code DoubleStream} consisting of the results of applying the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   144
     * given function to the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   145
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   146
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   147
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   148
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   149
     * @param mapper a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   150
     *               non-interfering, stateless</a> function to apply to each
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   151
     *               element
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   152
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   153
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   154
    DoubleStream mapToDouble(LongToDoubleFunction mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   155
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   156
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   157
     * Returns a stream consisting of the results of replacing each element of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   158
     * this stream with the contents of the stream produced by applying the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   159
     * provided mapping function to each element.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   160
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   161
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   162
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   163
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   164
     * @apiNote
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   165
     * The {@code flatMap()} operation has the effect of applying a one-to-many
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   166
     * tranformation to the elements of the stream, and then flattening the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   167
     * resulting elements into a new stream. For example, if {@code orders}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   168
     * is a stream of purchase orders, and each purchase order contains a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   169
     * collection of line items, then the following produces a stream of line
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   170
     * items:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   171
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   172
     *     orderStream.flatMap(order -> order.getLineItems().stream())...
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   173
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   174
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   175
     * @param mapper a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   176
     *               non-interfering, stateless</a> function to apply to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   177
     *               each element which produces an {@code LongStream} of new
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   178
     *               values
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   179
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   180
     * @see Stream#flatMap(Function)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   181
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   182
    LongStream flatMap(LongFunction<? extends LongStream> mapper);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   183
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   184
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   185
     * Returns a stream consisting of the distinct elements of this stream.
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 new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   191
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   192
    LongStream distinct();
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 in sorted
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   196
     * order.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   197
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   198
     * <p>This is a <a href="package-summary.html#StreamOps">stateful
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   199
     * intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   200
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   201
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   202
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   203
    LongStream sorted();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   204
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   205
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   206
     * Returns a stream consisting of the elements of this stream, additionally
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   207
     * performing the provided action on each element as elements are consumed
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   208
     * from the resulting stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   209
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   210
     * <p>This is an <a href="package-summary.html#StreamOps">intermediate
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   211
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   212
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   213
     * <p>For parallel stream pipelines, the action may be called at
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   214
     * whatever time and in whatever thread the element is made available by the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   215
     * upstream operation.  If the action modifies shared state,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   216
     * it is responsible for providing the required synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   217
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   218
     * @apiNote This method exists mainly to support debugging, where you want
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   219
     * to see the elements as they flow past a certain point in a pipeline:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   220
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   221
     *     list.stream()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   222
     *         .filter(filteringFunction)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   223
     *         .peek(e -> {System.out.println("Filtered value: " + e); });
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   224
     *         .map(mappingFunction)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   225
     *         .peek(e -> {System.out.println("Mapped value: " + e); });
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   226
     *         .collect(Collectors.toLongSummaryStastistics());
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   227
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   228
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   229
     * @param consumer a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   230
     *                 non-interfering</a> action to perform on the elements as
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   231
     *                 they are consumed from the stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   232
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   233
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   234
    LongStream peek(LongConsumer consumer);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   235
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   236
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   237
     * Returns a stream consisting of the elements of this stream, truncated
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   238
     * to be no longer than {@code maxSize} in length.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   239
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   240
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   241
     * stateful intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   242
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   243
     * @param maxSize the number of elements the stream should be limited to
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   244
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   245
     * @throws IllegalArgumentException if {@code maxSize} is negative
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   246
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   247
    LongStream limit(long maxSize);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   248
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   249
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   250
     * Returns a stream consisting of the remaining elements of this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   251
     * after indexing {@code startInclusive} elements into the stream. If the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   252
     * {@code startInclusive} index lies past the end of this stream then an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   253
     * empty stream will be returned.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   254
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   255
     * <p>This is a <a href="package-summary.html#StreamOps">stateful
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   256
     * intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   257
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   258
     * @param startInclusive the number of leading elements to skip
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   259
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   260
     * @throws IllegalArgumentException if {@code startInclusive} is negative
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   261
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   262
    LongStream substream(long startInclusive);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   263
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   264
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   265
     * Returns a stream consisting of the remaining elements of this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   266
     * after indexing {@code startInclusive} elements into the stream and
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   267
     * truncated to contain no more than {@code endExclusive - startInclusive}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   268
     * elements. If the {@code startInclusive} index lies past the end
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   269
     * of this stream then an empty stream will be returned.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   270
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   271
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   272
     * stateful intermediate operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   273
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   274
     * @param startInclusive the starting position of the substream, inclusive
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   275
     * @param endExclusive the ending position of the substream, exclusive
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   276
     * @return the new stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   277
     * @throws IllegalArgumentException if {@code startInclusive} or
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   278
     * {@code endExclusive} is negative or {@code startInclusive} is greater
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   279
     * than {@code endExclusive}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   280
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   281
    LongStream substream(long startInclusive, long endExclusive);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   282
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   283
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   284
     * Performs an action for each element of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   285
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   286
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   287
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   288
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   289
     * <p>For parallel stream pipelines, this operation does <em>not</em>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   290
     * guarantee to respect the encounter order of the stream, as doing so
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   291
     * would sacrifice the benefit of parallelism.  For any given element, the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   292
     * action may be performed at whatever time and in whatever thread the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   293
     * library chooses.  If the action accesses shared state, it is
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   294
     * responsible for providing the required synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   295
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   296
     * @param action a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   297
     *               non-interfering</a> action to perform on the elements
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   298
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   299
    void forEach(LongConsumer action);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   300
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   301
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   302
     * Performs an action for each element of this stream, guaranteeing that
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   303
     * each element is processed in encounter order for streams that have a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   304
     * defined encounter order.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   305
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   306
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   307
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   308
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   309
     * @param action a <a href="package-summary.html#NonInterference">
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   310
     *               non-interfering</a> action to perform on the elements
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   311
     * @see #forEach(LongConsumer)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   312
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   313
    void forEachOrdered(LongConsumer action);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   314
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   315
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   316
     * Returns an array containing the elements of this stream.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   317
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   318
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   319
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   320
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   321
     * @return an array containing the elements of this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   322
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   323
    long[] toArray();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   324
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   325
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   326
     * Performs a <a href="package-summary.html#Reduction">reduction</a> on the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   327
     * elements of this stream, using the provided identity value and an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   328
     * <a href="package-summary.html#Associativity">associative</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   329
     * accumulation function, and returns the reduced value.  This is equivalent
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   330
     * to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   331
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   332
     *     long result = identity;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   333
     *     for (long element : this stream)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   334
     *         result = accumulator.apply(result, element)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   335
     *     return result;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   336
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   337
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   338
     * but is not constrained to execute sequentially.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   339
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   340
     * <p>The {@code identity} value must be an identity for the accumulator
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   341
     * function. This means that for all {@code x},
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   342
     * {@code accumulator.apply(identity, x)} is equal to {@code x}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   343
     * The {@code accumulator} function must be an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   344
     * <a href="package-summary.html#Associativity">associative</a> function.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   345
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   346
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   347
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   348
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   349
     * @apiNote Sum, min, max, and average are all special cases of reduction.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   350
     * Summing a stream of numbers can be expressed as:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   351
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   352
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   353
     *     long sum = integers.reduce(0, (a, b) -> a+b);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   354
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   355
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   356
     * or more compactly:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   357
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   358
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   359
     *     long sum = integers.reduce(0, Long::sum);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   360
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   361
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   362
     * <p>While this may seem a more roundabout way to perform an aggregation
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   363
     * compared to simply mutating a running total in a loop, reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   364
     * operations parallelize more gracefully, without needing additional
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   365
     * synchronization and with greatly reduced risk of data races.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   366
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   367
     * @param identity the identity value for the accumulating function
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   368
     * @param op an <a href="package-summary.html#Associativity">associative</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   369
     *                    <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   370
     *                    stateless</a> function for combining two values
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   371
     * @return the result of the reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   372
     * @see #sum()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   373
     * @see #min()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   374
     * @see #max()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   375
     * @see #average()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   376
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   377
    long reduce(long identity, LongBinaryOperator op);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   378
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   379
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   380
     * Performs a <a href="package-summary.html#Reduction">reduction</a> on the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   381
     * elements of this stream, using an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   382
     * <a href="package-summary.html#Associativity">associative</a> accumulation
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   383
     * function, and returns an {@code OptionalLong} describing the reduced value,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   384
     * if any. This is equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   385
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   386
     *     boolean foundAny = false;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   387
     *     long result = null;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   388
     *     for (long element : this stream) {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   389
     *         if (!foundAny) {
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   390
     *             foundAny = true;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   391
     *             result = element;
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   392
     *         }
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   393
     *         else
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   394
     *             result = accumulator.apply(result, element);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   395
     *     }
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   396
     *     return foundAny ? OptionalLong.of(result) : OptionalLong.empty();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   397
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   398
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   399
     * but is not constrained to execute sequentially.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   400
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   401
     * <p>The {@code accumulator} function must be an
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   402
     * <a href="package-summary.html#Associativity">associative</a> function.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   403
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   404
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   405
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   406
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   407
     * @param op an <a href="package-summary.html#Associativity">associative</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   408
     *           <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   409
     *           stateless</a> function for combining two values
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(long, LongBinaryOperator)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   412
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   413
    OptionalLong reduce(LongBinaryOperator 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
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   418
     * reduction is one in which the reduced value is a mutable value holder,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   419
     * such as an {@code ArrayList}, and elements are incorporated by updating
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   420
     * the state of the result, rather than by replacing the result.  This
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
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   423
     *     R result = resultFactory.get();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   424
     *     for (long 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(long, LongBinaryOperator)}, {@code collect} operations
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   430
     * can be parallelized without requiring additional synchronization.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   431
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   432
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   433
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   434
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   435
     * @param <R> type of the result
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   436
     * @param resultFactory a function that creates a new result container.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   437
     *                      For a parallel execution, this function may be
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   438
     *                      called multiple times and must return a fresh value
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   439
     *                      each time.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   440
     * @param accumulator an <a href="package-summary.html#Associativity">associative</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   441
     *                    <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   442
     *                    stateless</a> function for incorporating an additional
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   443
     *                    element into a result
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   444
     * @param combiner an <a href="package-summary.html#Associativity">associative</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   445
     *                 <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   446
     *                 stateless</a> function for combining two values, which
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   447
     *                 must be compatible with the accumulator function
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   448
     * @return the result of the reduction
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   449
     * @see Stream#collect(Supplier, BiConsumer, BiConsumer)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   450
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   451
    <R> R collect(Supplier<R> resultFactory,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   452
                  ObjLongConsumer<R> accumulator,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   453
                  BiConsumer<R, R> combiner);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   454
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   455
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   456
     * Returns the sum of elements in this stream.  This is a special case
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   457
     * of a <a href="package-summary.html#MutableReduction">reduction</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   458
     * and is equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   459
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   460
     *     return reduce(0, Long::sum);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   461
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   462
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   463
     * @return the sum of elements in this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   464
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   465
    long sum();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   466
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   467
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   468
     * Returns an {@code OptionalLong} describing the minimum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   469
     * stream, or an empty optional if this stream is empty.  This is a special
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   470
     * case of a <a href="package-summary.html#MutableReduction">reduction</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   471
     * and is equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   472
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   473
     *     return reduce(Long::min);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   474
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   475
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   476
     * <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   477
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   478
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   479
     * @return an {@code OptionalLong} containing the minimum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   480
     * stream, or an empty {@code OptionalLong} if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   481
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   482
    OptionalLong min();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   483
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   484
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   485
     * Returns an {@code OptionalLong} describing the maximum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   486
     * stream, or an empty optional if this stream is empty.  This is a special
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   487
     * case of a <a href="package-summary.html#MutableReduction">reduction</a>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   488
     * and is equivalent to:
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   489
     * <pre>{@code
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   490
     *     return reduce(Long::max);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   491
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   492
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   493
     * <p>This is a <a href="package-summary.html#StreamOps">terminal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   494
     * operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   495
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   496
     * @return an {@code OptionalLong} containing the maximum element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   497
     * stream, or an empty {@code OptionalLong} if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   498
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   499
    OptionalLong max();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   500
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   501
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   502
     * Returns the count of elements in this stream.  This is a special case of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   503
     * a <a href="package-summary.html#MutableReduction">reduction</a> and is
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 map(e -> 1L).sum();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   507
     * }</pre>
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   508
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   509
     * <p>This is a <a href="package-summary.html#StreamOps">terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   510
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   511
     * @return the count of elements in this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   512
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   513
    long count();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   514
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   515
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   516
     * Returns an {@code OptionalDouble} describing the average of elements of
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   517
     * this stream, or an empty optional if this stream is empty.  This is a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   518
     * special case of a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   519
     * <a href="package-summary.html#MutableReduction">reduction</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   520
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   521
     * @return an {@code OptionalDouble} containing the average element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   522
     * stream, or an empty optional if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   523
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   524
    OptionalDouble average();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   525
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   526
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   527
     * Returns a {@code LongSummaryStatistics} describing various summary data
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   528
     * about the elements of this stream.  This is a special case of a
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   529
     * <a href="package-summary.html#MutableReduction">reduction</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   530
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   531
     * @return a {@code LongSummaryStatistics} describing various summary data
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   532
     * about the elements of this stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   533
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   534
    LongSummaryStatistics summaryStatistics();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   535
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   536
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   537
     * Returns whether any elements of this stream match the provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   538
     * predicate.  May not evaluate the predicate on all elements if not
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   539
     * necessary for determining the result.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   540
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   541
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   542
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   543
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   544
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   545
     *                  stateless</a> predicate to apply to elements of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   546
     *                  stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   547
     * @return {@code true} if any elements of the stream match the provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   548
     * predicate otherwise {@code false}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   549
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   550
    boolean anyMatch(LongPredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   551
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   552
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   553
     * Returns whether all elements of this stream match the provided predicate.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   554
     * May not evaluate the predicate on all elements if not necessary for
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   555
     * determining the result.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   556
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   557
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   558
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   559
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   560
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   561
     *                  stateless</a> predicate to apply to elements of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   562
     *                  stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   563
     * @return {@code true} if all elements of the stream match the provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   564
     * predicate otherwise {@code false}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   565
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   566
    boolean allMatch(LongPredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   567
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   568
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   569
     * Returns whether no elements of this stream match the provided  predicate.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   570
     * May not evaluate the predicate on all elements if not necessary for
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   571
     * determining the result.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   572
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   573
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   574
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   575
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   576
     * @param predicate a <a href="package-summary.html#NonInterference">non-interfering,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   577
     *                  stateless</a> predicate to apply to elements of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   578
     *                  stream
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   579
     * @return {@code true} if no elements of the stream match the provided
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   580
     * predicate otherwise {@code false}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   581
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   582
    boolean noneMatch(LongPredicate predicate);
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   583
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   584
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   585
     * Returns an {@link OptionalLong} describing the first element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   586
     * stream (in the encounter order), or an empty {@code OptionalLong} if the
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   587
     * stream is empty.  If the stream has no encounter order, than any element
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   588
     * may be returned.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   589
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   590
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   591
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   592
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   593
     * @return an {@code OptionalLong} describing the first element of this
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   594
     * stream, or an empty {@code OptionalLong} if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   595
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   596
    OptionalLong findFirst();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   597
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   598
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   599
     * Returns an {@link OptionalLong} describing some element of the stream, or
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   600
     * an empty {@code OptionalLong} if the stream is empty.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   601
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   602
     * <p>This is a <a href="package-summary.html#StreamOps">short-circuiting
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   603
     * terminal operation</a>.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   604
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   605
     * <p>The behavior of this operation is explicitly nondeterministic; it is
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   606
     * free to select any element in the stream.  This is to allow for maximal
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   607
     * performance in parallel operations; the cost is that multiple invocations
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   608
     * on the same source may not return the same result.  (If the first element
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   609
     * in the encounter order is desired, use {@link #findFirst()} instead.)
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   610
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   611
     * @return an {@code OptionalLong} describing some element of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   612
     * or an empty {@code OptionalLong} if the stream is empty
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   613
     * @see #findFirst()
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   614
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   615
    OptionalLong findAny();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   616
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   617
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   618
     * Returns a {@code DoubleStream} consisting of the elements of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   619
     * converted to {@code double}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   620
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   621
     * @return a {@code DoubleStream} consisting of the elements of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   622
     * converted to {@code double}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   623
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   624
    DoubleStream doubles();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   625
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   626
    /**
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   627
     * Returns a {@code Stream} consisting of the elements of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   628
     * each boxed to a {@code Long}.
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   629
     *
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   630
     * @return a {@code Stream} consistent of the elements of this stream,
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   631
     * each boxed to {@code Long}
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   632
     */
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   633
    Stream<Long> boxed();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   634
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   635
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   636
    LongStream sequential();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   637
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   638
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   639
    LongStream parallel();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   640
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   641
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   642
    PrimitiveIterator.OfLong iterator();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   643
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   644
    @Override
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   645
    Spliterator.OfLong spliterator();
87067e3340d3 8008682: Inital Streams public API
briangoetz
parents:
diff changeset
   646
}