本文整理匯總了Java中java.util.function.DoublePredicate類的典型用法代碼示例。如果您正苦於以下問題:Java DoublePredicate類的具體用法?Java DoublePredicate怎麽用?Java DoublePredicate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
DoublePredicate類屬於java.util.function包,在下文中一共展示了DoublePredicate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: DoublePredicate
import java.util.function.DoublePredicate; //導入依賴的package包/類
@Test
public void DoublePredicate()
{
// TODO - Convert the anonymous inner class to a lambda
DoublePredicate predicate = new DoublePredicate()
{
@Override
public boolean test(double value)
{
return value > 3.0;
}
};
List<Double> greaterThan =
DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).filter(predicate).boxed().collect(Collectors.toList());
Assert.assertEquals(Arrays.asList(4.0d, 5.0d), greaterThan);
List<Double> lessThanEqualTo =
DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).filter(predicate.negate()).boxed().collect(Collectors.toList());
Assert.assertEquals(Arrays.asList(1.0d, 2.0d, 3.0d), lessThanEqualTo);
Assert.assertTrue(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).anyMatch(predicate));
Assert.assertFalse(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).allMatch(predicate));
Assert.assertFalse(DoubleStream.of(1.0, 2.0, 3.0, 4.0, 5.0).noneMatch(predicate));
}
示例2: filter
import java.util.function.DoublePredicate; //導入依賴的package包/類
@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);
}
};
}
};
}
示例3: makeDouble
import java.util.function.DoublePredicate; //導入依賴的package包/類
/**
* 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);
}
示例4: shouldRequireNonNullCache
import java.util.function.DoublePredicate; //導入依賴的package包/類
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
// given
final ConcurrentMap<Double, Boolean> cache = null;
final DoublePredicate predicate = input -> true;
final DoubleFunction<Double> keyFunction = Double::valueOf;
// when
thrown.expect(NullPointerException.class);
thrown.expectMessage("Provide an empty map instead of NULL.");
// then
new ConcurrentMapBasedDoublePredicateMemoizer<>(cache, keyFunction, predicate);
}
示例5: shouldWrapExecutionExceptionInMemoizationException
import java.util.function.DoublePredicate; //導入依賴的package包/類
/**
* @throws ExecutionException
* Added for the call to 'cache.get(..)'.
*/
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
// given
final DoublePredicate predicate = a -> true;
final DoubleFunction<String> keyFunction = a -> "key";
final Cache<String, Boolean> cache = Mockito.mock(Cache.class);
given(cache.get(any(), any())).willThrow(ExecutionException.class);
final GuavaCacheBasedDoublePredicateMemoizer<String> memoizer = new GuavaCacheBasedDoublePredicateMemoizer<>(
cache, keyFunction, predicate);
// when
thrown.expect(MemoizationException.class);
// then
memoizer.test(123.456D);
}
示例6: OnGlobalAttributeCondition
import java.util.function.DoublePredicate; //導入依賴的package包/類
public OnGlobalAttributeCondition (IGame game,
AttributeType attributeType,
DoublePredicate valueCheck,
IEventPackage otherPackage,
IEventPackage globalPackage) {
myGame = game;
myAttributeType = attributeType;
myValueCheck = valueCheck;
myOtherPackage = otherPackage;
myGlobalPackage = globalPackage;
}
示例7: OnSpriteAttributeCondition
import java.util.function.DoublePredicate; //導入依賴的package包/類
public OnSpriteAttributeCondition (IGame game,
AttributeType attributeType,
DoublePredicate valueCheck,
IEventPackage spritePackage,
IEventPackage otherPackage,
IEventPackage globalPackage) {
myGame = game;
myAttributeType = attributeType;
myValueCheck = valueCheck;
mySpritePackage = spritePackage;
myOtherPackage = otherPackage;
myGlobalPackage = globalPackage;
}
示例8: generateDouble
import java.util.function.DoublePredicate; //導入依賴的package包/類
public DoublePredicate generateDouble (String value, String type) {
double valToCompare = Double.parseDouble(value);
if (type.equals("==")) {
return new EqualsDoublePredicate(valToCompare);
}
else if (type.equals(">")) {
return new GreaterThanDoublePredicate(valToCompare);
}
else {
return new LessThanDoublePredicate(valToCompare);
}
}
示例9: testDoublePredicate
import java.util.function.DoublePredicate; //導入依賴的package包/類
@Test public void testDoublePredicate() {
DoublePredicate isCorrect = (d) -> {
return d > 2894d;
};
assertTrue(isCorrect.test(2898d));
assertFalse(isCorrect.test(2751d));
assertFalse(isCorrect.test(38L));
}
示例10: assertDoublePredicates
import java.util.function.DoublePredicate; //導入依賴的package包/類
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());
}
}
示例11: testDoubleStream
import java.util.function.DoublePredicate; //導入依賴的package包/類
@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));
}
}
}
示例12: should_verify_an_actual_double_predicate_is_conform_to_an_expected_result
import java.util.function.DoublePredicate; //導入依賴的package包/類
@Test
public void should_verify_an_actual_double_predicate_is_conform_to_an_expected_result() {
assertThat(resultOf(() -> {
gwtMock.whenAnEventHappensInRelationToAnActionOfTheConsumer();
return (DoublePredicate) number -> number < 100;
}).accepts(99)).hasSameClassAs(assertThat((DoublePredicate) t -> t == 0));
}
示例13: RangeOfDoubles
import java.util.function.DoublePredicate; //導入依賴的package包/類
/**
* Constructor
* @param start the start for range, inclusive
* @param end the end for range, exclusive
* @param step the step increment
* @param excludes optional predicate to exclude elements in this range
*/
RangeOfDoubles(double start, double end, double step, DoublePredicate excludes) {
super(start, end);
this.start = start;
this.end = end;
this.step = step;
this.ascend = start <= end;
this.excludes = excludes;
}
示例14: JCacheBasedDoublePredicateMemoizer
import java.util.function.DoublePredicate; //導入依賴的package包/類
JCacheBasedDoublePredicateMemoizer(
final Cache<KEY, Boolean> cache,
final DoubleFunction<KEY> keyFunction,
final DoublePredicate predicate) {
super(cache);
this.keyFunction = keyFunction;
this.predicate = predicate;
}
示例15: ConcurrentMapBasedDoublePredicateMemoizer
import java.util.function.DoublePredicate; //導入依賴的package包/類
@SuppressWarnings(CompilerWarnings.NLS)
ConcurrentMapBasedDoublePredicateMemoizer(
final ConcurrentMap<KEY, Boolean> cache,
final DoubleFunction<KEY> keyFunction,
final DoublePredicate predicate) {
super(cache);
this.keyFunction = keyFunction;
this.predicate = requireNonNull(predicate,
"Cannot memoize a NULL Predicate - provide an actual Predicate to fix this.");
}