jdk/src/share/classes/java/util/stream/MatchOps.java
author psandoz
Wed, 17 Apr 2013 11:34:31 +0200
changeset 17168 b7d3500f2516
parent 17163 6a5e9b4f27d2
child 17454 8452c073f7fc
permissions -rw-r--r--
8011426: java.util collection Spliterator implementations Summary: Spliterator implementations for collection classes in java.util. Reviewed-by: mduigou, briangoetz Contributed-by: Doug Lea <dl@cs.oswego.edu>, Paul Sandoz <paul.sandoz@oracle.com>
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.Objects;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    28
import java.util.Spliterator;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    29
import java.util.function.DoublePredicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    30
import java.util.function.IntPredicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    31
import java.util.function.LongPredicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    32
import java.util.function.Predicate;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    33
import java.util.function.Supplier;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    34
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
 * Factory for instances of a short-circuiting {@code TerminalOp} that implement
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    37
 * quantified predicate matching on the elements of a stream. Supported variants
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    38
 * include match-all, match-any, and match-none.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    39
 *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    40
 * @since 1.8
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    41
 */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    42
final class MatchOps {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    43
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    44
    private MatchOps() { }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    45
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
     * Enum describing quantified match options -- all match, any match, none
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    48
     * match.
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
    enum MatchKind {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    51
        /** Do all elements match the predicate? */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    52
        ANY(true, true),
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    53
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    54
        /** Do any elements match the predicate? */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    55
        ALL(false, false),
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
        /** Do no elements match the predicate? */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    58
        NONE(true, false);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    59
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    60
        private final boolean stopOnPredicateMatches;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    61
        private final boolean shortCircuitResult;
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
        private MatchKind(boolean stopOnPredicateMatches,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    64
                          boolean shortCircuitResult) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    65
            this.stopOnPredicateMatches = stopOnPredicateMatches;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    66
            this.shortCircuitResult = shortCircuitResult;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    67
        }
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    70
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    71
     * Constructs a quantified predicate matcher for a Stream.
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
     * @param <T> the type of stream elements
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    74
     * @param predicate the {@code Predicate} to apply to stream elements
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    75
     * @param matchKind the kind of quantified match (all, any, none)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    76
     * @return a {@code TerminalOp} implementing the desired quantified match
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    77
     *         criteria
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    78
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    79
    public static <T> TerminalOp<T, Boolean> makeRef(Predicate<? super T> predicate,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    80
            MatchKind matchKind) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    81
        Objects.requireNonNull(predicate);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    82
        Objects.requireNonNull(matchKind);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    83
        class MatchSink extends BooleanTerminalSink<T> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    84
            MatchSink() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    85
                super(matchKind);
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    88
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    89
            public void accept(T t) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    90
                if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    91
                    stop = true;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    92
                    value = matchKind.shortCircuitResult;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    93
                }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    94
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    95
        }
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
        // @@@ Workaround for JDK-8011591 -- when fixed, replace s with constructor ref
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    98
        Supplier<BooleanTerminalSink<T>> s = new Supplier<BooleanTerminalSink<T>>() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
    99
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   100
            public BooleanTerminalSink<T> get() {return new MatchSink();}
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   101
        };
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   102
        return new MatchOp<>(StreamShape.REFERENCE, matchKind, s);
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   105
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   106
     * Constructs a quantified predicate matcher for an {@code IntStream}.
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
     * @param predicate the {@code Predicate} to apply to stream elements
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   109
     * @param matchKind the kind of quantified match (all, any, none)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   110
     * @return a {@code TerminalOp} implementing the desired quantified match
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   111
     *         criteria
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   112
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   113
    public static TerminalOp<Integer, Boolean> makeInt(IntPredicate predicate,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   114
                                                       MatchKind matchKind) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   115
        Objects.requireNonNull(predicate);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   116
        Objects.requireNonNull(matchKind);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   117
        class MatchSink extends BooleanTerminalSink<Integer> implements Sink.OfInt {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   118
            MatchSink() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   119
                super(matchKind);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   120
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   121
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   122
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   123
            public void accept(int t) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   124
                if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   125
                    stop = true;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   126
                    value = matchKind.shortCircuitResult;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   127
                }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   128
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   129
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   130
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   131
        // @@@ Workaround for JDK-8011591 -- when fixed, replace s with constructor ref
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   132
        Supplier<BooleanTerminalSink<Integer>> s = new Supplier<BooleanTerminalSink<Integer>>() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   133
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   134
            public BooleanTerminalSink<Integer> get() {return new MatchSink();}
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   135
        };
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   136
        return new MatchOp<>(StreamShape.INT_VALUE, matchKind, s);
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
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   140
     * Constructs a quantified predicate matcher for a {@code LongStream}.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   141
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   142
     * @param predicate the {@code Predicate} to apply to stream elements
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   143
     * @param matchKind the kind of quantified match (all, any, none)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   144
     * @return a {@code TerminalOp} implementing the desired quantified match
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   145
     *         criteria
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   146
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   147
    public static TerminalOp<Long, Boolean> makeLong(LongPredicate predicate,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   148
                                                     MatchKind matchKind) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   149
        Objects.requireNonNull(predicate);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   150
        Objects.requireNonNull(matchKind);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   151
        class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   152
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   153
            MatchSink() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   154
                super(matchKind);
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   157
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   158
            public void accept(long t) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   159
                if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   160
                    stop = true;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   161
                    value = matchKind.shortCircuitResult;
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
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   165
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   166
        // @@@ Workaround for JDK-8011591 -- when fixed, replace s with constructor ref
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   167
        Supplier<BooleanTerminalSink<Long>> s = new Supplier<BooleanTerminalSink<Long>>() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   168
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   169
            public BooleanTerminalSink<Long> get() {return new MatchSink();}
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   170
        };
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   171
        return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, s);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   172
    }
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
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   175
     * Constructs a quantified predicate matcher for a {@code DoubleStream}.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   176
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   177
     * @param predicate the {@code Predicate} to apply to stream elements
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   178
     * @param matchKind the kind of quantified match (all, any, none)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   179
     * @return a {@code TerminalOp} implementing the desired quantified match
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   180
     *         criteria
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
    public static TerminalOp<Double, Boolean> makeDouble(DoublePredicate predicate,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   183
                                                         MatchKind matchKind) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   184
        Objects.requireNonNull(predicate);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   185
        Objects.requireNonNull(matchKind);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   186
        class MatchSink extends BooleanTerminalSink<Double> implements Sink.OfDouble {
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
            MatchSink() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   189
                super(matchKind);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   190
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   191
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   192
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   193
            public void accept(double t) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   194
                if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   195
                    stop = true;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   196
                    value = matchKind.shortCircuitResult;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   197
                }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   198
            }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   199
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   200
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   201
        // @@@ Workaround for JDK-8011591 -- when fixed, replace s with constructor ref
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   202
        Supplier<BooleanTerminalSink<Double>> s = new Supplier<BooleanTerminalSink<Double>>() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   203
            @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   204
            public BooleanTerminalSink<Double> get() {return new MatchSink();}
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
        return new MatchOp<>(StreamShape.DOUBLE_VALUE, matchKind, s);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   207
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   208
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
     * A short-circuiting {@code TerminalOp} that evaluates a predicate on the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   211
     * elements of a stream and determines whether all, any or none of those
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   212
     * elements match the predicate.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   213
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   214
     * @param <T> the output type of the stream pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   215
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   216
    private static final class MatchOp<T> implements TerminalOp<T, Boolean> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   217
        private final StreamShape inputShape;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   218
        final MatchKind matchKind;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   219
        final Supplier<BooleanTerminalSink<T>> sinkSupplier;
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
        /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   222
         * Constructs a {@code MatchOp}.
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   223
         *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   224
         * @param shape the output shape of the stream pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   225
         * @param matchKind the kind of quantified match (all, any, none)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   226
         * @param sinkSupplier {@code Supplier} for a {@code Sink} of the
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   227
         *        appropriate shape which implements the matching operation
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   228
         */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   229
        MatchOp(StreamShape shape,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   230
                MatchKind matchKind,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   231
                Supplier<BooleanTerminalSink<T>> sinkSupplier) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   232
            this.inputShape = shape;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   233
            this.matchKind = matchKind;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   234
            this.sinkSupplier = sinkSupplier;
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   237
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   238
        public int getOpFlags() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   239
            return StreamOpFlag.IS_SHORT_CIRCUIT | StreamOpFlag.NOT_ORDERED;
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
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   243
        public StreamShape inputShape() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   244
            return inputShape;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   245
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   246
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   247
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   248
        public <S> Boolean evaluateSequential(PipelineHelper<T> helper,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   249
                                              Spliterator<S> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   250
            return helper.wrapAndCopyInto(sinkSupplier.get(), spliterator).getAndClearState();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   251
        }
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
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   254
        public <S> Boolean evaluateParallel(PipelineHelper<T> helper,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   255
                                            Spliterator<S> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   256
            // Approach for parallel implementation:
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   257
            // - Decompose as per usual
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   258
            // - run match on leaf chunks, call result "b"
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   259
            // - if b == matchKind.shortCircuitOn, complete early and return b
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   260
            // - else if we complete normally, return !shortCircuitOn
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   261
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   262
            return new MatchTask<>(this, helper, spliterator).invoke();
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   266
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   267
     * Boolean specific terminal sink to avoid the boxing costs when returning
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   268
     * results.  Subclasses implement the shape-specific functionality.
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
     * @param <T> The output type of the stream pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   271
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   272
    private static abstract class BooleanTerminalSink<T> implements Sink<T> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   273
        boolean stop;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   274
        boolean value;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   275
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   276
        BooleanTerminalSink(MatchKind matchKind) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   277
            value = !matchKind.shortCircuitResult;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   278
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   279
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   280
        public boolean getAndClearState() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   281
            return value;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   282
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   283
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   284
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   285
        public boolean cancellationRequested() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   286
            return stop;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   287
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   288
    }
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
    /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   291
     * ForkJoinTask implementation to implement a parallel short-circuiting
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   292
     * quantified match
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   293
     *
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   294
     * @param <P_IN> the type of source elements for the pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   295
     * @param <P_OUT> the type of output elements for the pipeline
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   296
     */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   297
    private static final class MatchTask<P_IN, P_OUT>
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   298
            extends AbstractShortCircuitTask<P_IN, P_OUT, Boolean, MatchTask<P_IN, P_OUT>> {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   299
        private final MatchOp<P_OUT> op;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   300
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   301
        /**
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   302
         * Constructor for root node
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   303
         */
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   304
        MatchTask(MatchOp<P_OUT> op, PipelineHelper<P_OUT> helper,
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   305
                  Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   306
            super(helper, spliterator);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   307
            this.op = op;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   308
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   309
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
         * Constructor for non-root node
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
        MatchTask(MatchTask<P_IN, P_OUT> parent, Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   314
            super(parent, spliterator);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   315
            this.op = parent.op;
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
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   318
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   319
        protected MatchTask<P_IN, P_OUT> makeChild(Spliterator<P_IN> spliterator) {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   320
            return new MatchTask<>(this, spliterator);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   321
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   322
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   323
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   324
        protected Boolean doLeaf() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   325
            boolean b = helper.wrapAndCopyInto(op.sinkSupplier.get(), spliterator).getAndClearState();
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   326
            if (b == op.matchKind.shortCircuitResult)
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   327
                shortCircuit(b);
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   328
            return null;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   329
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   330
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   331
        @Override
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   332
        protected Boolean getEmptyResult() {
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   333
            return !op.matchKind.shortCircuitResult;
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   334
        }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   335
    }
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   336
}
6a5e9b4f27d2 8008670: Initial java.util.stream putback -- internal API classes
mduigou
parents:
diff changeset
   337