jdk/src/share/classes/java/util/stream/FindOps.java
author darcy
Wed, 10 Jul 2013 11:05:39 -0700
changeset 18796 486b43748d9b
parent 17163 6a5e9b4f27d2
child 19218 8e7212b90b81
permissions -rw-r--r--
8020294: Fix doclint issues in java.util.Spliterator Reviewed-by: psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
17163
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     1
/*
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     2
 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     4
 *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    10
 *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    15
 * accompanied this code).
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    16
 *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    20
 *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    23
 * questions.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    24
 */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    25
package java.util.stream;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    26
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    27
import java.util.Optional;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    28
import java.util.OptionalDouble;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    29
import java.util.OptionalInt;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    30
import java.util.OptionalLong;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    31
import java.util.Spliterator;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    32
import java.util.concurrent.CountedCompleter;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    33
import java.util.function.Predicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    34
import java.util.function.Supplier;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    35
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    36
/**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    37
 * Factory for instances of a short-circuiting {@code TerminalOp} that searches
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    38
 * for an element in a stream pipeline, and terminates when it finds one.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    39
 * Supported variants include find-first (find the first element in the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    40
 * encounter order) and find-any (find any element, may not be the first in
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    41
 * encounter order.)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    42
 *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    43
 * @since 1.8
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    44
 */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    45
final class FindOps {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    46
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    47
    private FindOps() { }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    48
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    49
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    50
     * Constructs a {@code TerminalOp} for streams of objects.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    51
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    52
     * @param <T> the type of elements of the stream
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    53
     * @param mustFindFirst whether the {@code TerminalOp} must produce the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    54
     *        first element in the encounter order
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    55
     * @return a {@code TerminalOp} implementing the find operation
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    56
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    57
    public static <T> TerminalOp<T, Optional<T>> makeRef(boolean mustFindFirst) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    58
        return new FindOp<>(mustFindFirst, StreamShape.REFERENCE, Optional.empty(),
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    59
                            Optional::isPresent, FindSink.OfRef::new);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    60
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    61
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    62
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    63
     * Constructs a {@code TerminalOp} for streams of ints.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    64
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    65
     * @param mustFindFirst whether the {@code TerminalOp} must produce the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    66
     *        first element in the encounter order
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    67
     * @return a {@code TerminalOp} implementing the find operation
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    68
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    69
    public static TerminalOp<Integer, OptionalInt> makeInt(boolean mustFindFirst) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    70
        return new FindOp<>(mustFindFirst, StreamShape.INT_VALUE, OptionalInt.empty(),
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    71
                            OptionalInt::isPresent, FindSink.OfInt::new);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    72
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    73
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    74
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    75
     * Constructs a {@code TerminalOp} for streams of longs.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    76
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    77
     * @param mustFindFirst whether the {@code TerminalOp} must produce the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    78
     *        first element in the encounter order
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    79
     * @return a {@code TerminalOp} implementing the find operation
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    80
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    81
    public static TerminalOp<Long, OptionalLong> makeLong(boolean mustFindFirst) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    82
        return new FindOp<>(mustFindFirst, StreamShape.LONG_VALUE, OptionalLong.empty(),
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    83
                            OptionalLong::isPresent, FindSink.OfLong::new);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    84
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    85
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    86
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    87
     * Constructs a {@code FindOp} for streams of doubles.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    88
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    89
     * @param mustFindFirst whether the {@code TerminalOp} must produce the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    90
     *        first element in the encounter order
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    91
     * @return a {@code TerminalOp} implementing the find operation
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    92
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    93
    public static TerminalOp<Double, OptionalDouble> makeDouble(boolean mustFindFirst) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    94
        return new FindOp<>(mustFindFirst, StreamShape.DOUBLE_VALUE, OptionalDouble.empty(),
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    95
                            OptionalDouble::isPresent, FindSink.OfDouble::new);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    96
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    97
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    98
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    99
     * A short-circuiting {@code TerminalOp} that searches for an element in a
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   100
     * stream pipeline, and terminates when it finds one.  Implements both
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   101
     * find-first (find the first element in the encounter order) and find-any
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   102
     * (find any element, may not be the first in encounter order.)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   103
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   104
     * @param <T> the output type of the stream pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   105
     * @param <O> the result type of the find operation, typically an optional
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   106
     *        type
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   107
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   108
    private static final class FindOp<T, O> implements TerminalOp<T, O> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   109
        private final StreamShape shape;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   110
        final boolean mustFindFirst;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   111
        final O emptyValue;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   112
        final Predicate<O> presentPredicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   113
        final Supplier<TerminalSink<T, O>> sinkSupplier;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   114
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   115
        /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   116
         * Constructs a {@code FindOp}.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   117
         *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   118
         * @param mustFindFirst if true, must find the first element in
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   119
         *        encounter order, otherwise can find any element
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   120
         * @param shape stream shape of elements to search
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   121
         * @param emptyValue result value corresponding to "found nothing"
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   122
         * @param presentPredicate {@code Predicate} on result value
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   123
         *        corresponding to "found something"
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   124
         * @param sinkSupplier supplier for a {@code TerminalSink} implementing
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   125
         *        the matching functionality
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   126
         */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   127
        FindOp(boolean mustFindFirst,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   128
                       StreamShape shape,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   129
                       O emptyValue,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   130
                       Predicate<O> presentPredicate,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   131
                       Supplier<TerminalSink<T, O>> sinkSupplier) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   132
            this.mustFindFirst = mustFindFirst;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   133
            this.shape = shape;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   134
            this.emptyValue = emptyValue;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   135
            this.presentPredicate = presentPredicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   136
            this.sinkSupplier = sinkSupplier;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   137
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   138
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   139
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   140
        public int getOpFlags() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   141
            return StreamOpFlag.IS_SHORT_CIRCUIT | (mustFindFirst ? 0 : StreamOpFlag.NOT_ORDERED);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   142
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   143
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   144
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   145
        public StreamShape inputShape() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   146
            return shape;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   147
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   148
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   149
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   150
        public <S> O evaluateSequential(PipelineHelper<T> helper,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   151
                                        Spliterator<S> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   152
            O result = helper.wrapAndCopyInto(sinkSupplier.get(), spliterator).get();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   153
            return result != null ? result : emptyValue;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   154
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   155
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   156
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   157
        public <P_IN> O evaluateParallel(PipelineHelper<T> helper,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   158
                                         Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   159
            return new FindTask<>(this, helper, spliterator).invoke();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   160
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   161
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   162
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   163
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   164
     * Implementation of @{code TerminalSink} that implements the find
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   165
     * functionality, requesting cancellation when something has been found
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   166
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   167
     * @param <T> The type of input element
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   168
     * @param <O> The result type, typically an optional type
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   169
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   170
    private static abstract class FindSink<T, O> implements TerminalSink<T, O> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   171
        boolean hasValue;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   172
        T value;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   173
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   174
        FindSink() {} // Avoid creation of special accessor
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   175
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   176
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   177
        public void accept(T value) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   178
            if (!hasValue) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   179
                hasValue = true;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   180
                this.value = value;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   181
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   182
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   183
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   184
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   185
        public boolean cancellationRequested() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   186
            return hasValue;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   187
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   188
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   189
        /** Specialization of {@code FindSink} for reference streams */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   190
        static final class OfRef<T> extends FindSink<T, Optional<T>> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   191
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   192
            public Optional<T> get() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   193
                return hasValue ? Optional.of(value) : null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   194
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   195
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   196
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   197
        /** Specialization of {@code FindSink} for int streams */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   198
        static final class OfInt extends FindSink<Integer, OptionalInt>
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   199
                implements Sink.OfInt {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   200
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   201
            public void accept(int value) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   202
                // Boxing is OK here, since few values will actually flow into the sink
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   203
                accept((Integer) value);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   204
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   205
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   206
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   207
            public OptionalInt get() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   208
                return hasValue ? OptionalInt.of(value) : null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   209
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   210
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   211
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   212
        /** Specialization of {@code FindSink} for long streams */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   213
        static final class OfLong extends FindSink<Long, OptionalLong>
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   214
                implements Sink.OfLong {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   215
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   216
            public void accept(long value) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   217
                // Boxing is OK here, since few values will actually flow into the sink
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   218
                accept((Long) value);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   219
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   220
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   221
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   222
            public OptionalLong get() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   223
                return hasValue ? OptionalLong.of(value) : null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   224
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   225
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   226
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   227
        /** Specialization of {@code FindSink} for double streams */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   228
        static final class OfDouble extends FindSink<Double, OptionalDouble>
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   229
                implements Sink.OfDouble {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   230
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   231
            public void accept(double value) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   232
                // Boxing is OK here, since few values will actually flow into the sink
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   233
                accept((Double) value);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   234
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   235
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   236
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   237
            public OptionalDouble get() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   238
                return hasValue ? OptionalDouble.of(value) : null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   239
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   240
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   241
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   242
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   243
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   244
     * {@code ForkJoinTask} implementing parallel short-circuiting search
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   245
     * @param <P_IN> Input element type to the stream pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   246
     * @param <P_OUT> Output element type from the stream pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   247
     * @param <O> Result type from the find operation
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   248
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   249
    private static final class FindTask<P_IN, P_OUT, O>
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   250
            extends AbstractShortCircuitTask<P_IN, P_OUT, O, FindTask<P_IN, P_OUT, O>> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   251
        private final FindOp<P_OUT, O> op;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   252
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   253
        FindTask(FindOp<P_OUT, O> op,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   254
                 PipelineHelper<P_OUT> helper,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   255
                 Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   256
            super(helper, spliterator);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   257
            this.op = op;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   258
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   259
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   260
        FindTask(FindTask<P_IN, P_OUT, O> parent, Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   261
            super(parent, spliterator);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   262
            this.op = parent.op;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   263
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   264
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   265
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   266
        protected FindTask<P_IN, P_OUT, O> makeChild(Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   267
            return new FindTask<>(this, spliterator);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   268
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   269
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   270
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   271
        protected O getEmptyResult() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   272
            return op.emptyValue;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   273
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   274
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   275
        private void foundResult(O answer) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   276
            if (isLeftmostNode())
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   277
                shortCircuit(answer);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   278
            else
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   279
                cancelLaterNodes();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   280
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   281
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   282
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   283
        protected O doLeaf() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   284
            O result = helper.wrapAndCopyInto(op.sinkSupplier.get(), spliterator).get();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   285
            if (!op.mustFindFirst) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   286
                if (result != null)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   287
                    shortCircuit(result);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   288
                return null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   289
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   290
            else {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   291
                if (result != null) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   292
                    foundResult(result);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   293
                    return result;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   294
                }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   295
                else
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   296
                    return null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   297
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   298
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   299
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   300
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   301
        public void onCompletion(CountedCompleter<?> caller) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   302
            if (op.mustFindFirst) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   303
                    for (FindTask<P_IN, P_OUT, O> child = leftChild, p = null; child != p;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   304
                         p = child, child = rightChild) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   305
                    O result = child.getLocalResult();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   306
                    if (result != null && op.presentPredicate.test(result)) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   307
                        setLocalResult(result);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   308
                        foundResult(result);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   309
                        break;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   310
                    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   311
                }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   312
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   313
            super.onCompletion(caller);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   314
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   315
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   316
}
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   317