java.util.function.DoublePredicate Java Examples

The following examples show how to use java.util.function.DoublePredicate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DoublePipeline.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #2
Source File: DoublePipeline.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #3
Source File: MatchOps.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code DoubleStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Double, Boolean> makeDouble(DoublePredicate predicate,
                                                     MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Double> implements Sink.OfDouble {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(double t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.DOUBLE_VALUE, matchKind, MatchSink::new);
}
 
Example #4
Source File: MatchOps.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code DoubleStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Double, Boolean> makeDouble(DoublePredicate predicate,
                                                     MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Double> implements Sink.OfDouble {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(double t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.DOUBLE_VALUE, matchKind, MatchSink::new);
}
 
Example #5
Source File: MatchOps.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code DoubleStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Double, Boolean> makeDouble(DoublePredicate predicate,
                                                     MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Double> implements Sink.OfDouble {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(double t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.DOUBLE_VALUE, matchKind, MatchSink::new);
}
 
Example #6
Source File: DoublePipeline.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #7
Source File: DoublePipeline.java    From desugar_jdk_libs with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #8
Source File: DoublePipeline.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #9
Source File: DoublePipeline.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #10
Source File: DoublePipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #11
Source File: MatchOps.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a quantified predicate matcher for a {@code DoubleStream}.
 *
 * @param predicate the {@code Predicate} to apply to stream elements
 * @param matchKind the kind of quantified match (all, any, none)
 * @return a {@code TerminalOp} implementing the desired quantified match
 *         criteria
 */
public static TerminalOp<Double, Boolean> makeDouble(DoublePredicate predicate,
                                                     MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Double> implements Sink.OfDouble {

        MatchSink() {
            super(matchKind);
        }

        @Override
        public void accept(double t) {
            if (!stop && predicate.test(t) == matchKind.stopOnPredicateMatches) {
                stop = true;
                value = matchKind.shortCircuitResult;
            }
        }
    }

    return new MatchOp<>(StreamShape.DOUBLE_VALUE, matchKind, MatchSink::new);
}
 
Example #12
Source File: DoublePipeline.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
@Override
public final DoubleStream filter(DoublePredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Double>(this, StreamShape.DOUBLE_VALUE,
                                   StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
            return new Sink.ChainedDouble<Double>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(double t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
Example #13
Source File: MatchOpTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void assertDoublePredicates(Supplier<DoubleStream> source, Kind kind, DoublePredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = doubleKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #14
Source File: TestLambdaJavaInterfaces.java    From openjdk-systemtest with Apache License 2.0 5 votes vote down vote up
@Test public void testDoublePredicate() {
	DoublePredicate isCorrect = (d) -> {
		return d > 2894d;
	};

	assertTrue(isCorrect.test(2898d));
	assertFalse(isCorrect.test(2751d));
	assertFalse(isCorrect.test(38L));
}
 
Example #15
Source File: MatchOpTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleStream(String name, TestData.OfDouble data) {
    for (DoublePredicate p : DOUBLE_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpFalse), doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpEven), doubleKinds.get(kind).apply(p));
        }
    }
}
 
Example #16
Source File: MatchOpTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void assertDoublePredicates(Supplier<DoubleStream> source, Kind kind, DoublePredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = doubleKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #17
Source File: MatchOpTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleStream(String name, TestData.OfDouble data) {
    for (DoublePredicate p : DOUBLE_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpFalse), doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpEven), doubleKinds.get(kind).apply(p));
        }
    }
}
 
Example #18
Source File: MatchOpTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void assertDoublePredicates(Supplier<DoubleStream> source, Kind kind, DoublePredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = doubleKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #19
Source File: MatchOpTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void assertDoublePredicates(Supplier<DoubleStream> source, Kind kind, DoublePredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = doubleKinds.get(kind).apply(predicates[i]).apply(source.get());
        assertEquals(answers[i], match, kind.toString() + predicates[i].toString());
    }
}
 
Example #20
Source File: MatchOpTest.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleStream(String name, TestData.OfDouble data) {
    for (DoublePredicate p : DOUBLE_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpFalse), doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpEven), doubleKinds.get(kind).apply(p));
        }
    }
}
 
Example #21
Source File: MatchOpTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "DoubleStreamTestData", dataProviderClass = DoubleStreamTestDataProvider.class)
public void testDoubleStream(String name, TestData.OfDouble data) {
    for (DoublePredicate p : DOUBLE_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpFalse), doubleKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(dpEven), doubleKinds.get(kind).apply(p));
        }
    }
}
 
Example #22
Source File: WhileOps.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
OfDouble(Spliterator.OfDouble s, boolean noSplitting, DoublePredicate p) {
    super(s, noSplitting);
    this.p = p;
}
 
Example #23
Source File: DoublePipeline.java    From jdk1.8-source-analysis with Apache License 2.0 4 votes vote down vote up
@Override
public final boolean anyMatch(DoublePredicate predicate) {
    return evaluate(MatchOps.makeDouble(predicate, MatchOps.MatchKind.ANY));
}
 
Example #24
Source File: DoublePipeline.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public final DoubleStream takeWhile(DoublePredicate predicate) {
    return WhileOps.makeTakeWhileDouble(this, predicate);
}
 
Example #25
Source File: DoublePipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean noneMatch(DoublePredicate predicate) {
    return evaluate(MatchOps.makeDouble(predicate, MatchOps.MatchKind.NONE));
}
 
Example #26
Source File: DoublePipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean allMatch(DoublePredicate predicate) {
    return evaluate(MatchOps.makeDouble(predicate, MatchOps.MatchKind.ALL));
}
 
Example #27
Source File: DoublePipeline.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean noneMatch(DoublePredicate predicate) {
    return evaluate(MatchOps.makeDouble(predicate, MatchOps.MatchKind.NONE));
}
 
Example #28
Source File: DoublePipeline.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Override
public final boolean anyMatch(DoublePredicate predicate) {
    return evaluate(MatchOps.makeDouble(predicate, MatchOps.MatchKind.ANY));
}
 
Example #29
Source File: OptionalDouble.java    From metanome-algorithms with Apache License 2.0 4 votes vote down vote up
public OptionalDouble filter(@NonNull DoublePredicate predicate) {
	if (!optional.isPresent()) {
		return this;
	}
	return predicate.test(optional.getAsDouble()) ? this : empty();
}
 
Example #30
Source File: DoublePipeline.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
@Override
public final DoubleStream dropWhile(DoublePredicate predicate) {
    return WhileOps.makeDropWhileDouble(this, predicate);
}