當前位置: 首頁>>代碼示例>>Java>>正文


Java DoublePredicate類代碼示例

本文整理匯總了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));
}
 
開發者ID:BNYMellon,項目名稱:CodeKatas,代碼行數:23,代碼來源:PrimitiveFunctionalInterfaceTest.java

示例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);
                }
            };
        }
    };
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:DoublePipeline.java

示例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);
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:MatchOps.java

示例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);
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:19,代碼來源:ConcurrentMapBasedDoublePredicateMemoizerTest.java

示例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);
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:22,代碼來源:GuavaCacheBasedDoublePredicateMemoizerTest.java

示例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;
}
 
開發者ID:tomrom95,項目名稱:GameAuthoringEnvironment,代碼行數:12,代碼來源:OnGlobalAttributeCondition.java

示例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;

}
 
開發者ID:tomrom95,項目名稱:GameAuthoringEnvironment,代碼行數:15,代碼來源:OnSpriteAttributeCondition.java

示例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);
    }

}
 
開發者ID:tomrom95,項目名稱:GameAuthoringEnvironment,代碼行數:14,代碼來源:PredicateGenerator.java

示例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));
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-systemtest,代碼行數:10,代碼來源:TestLambdaJavaInterfaces.java

示例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());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:8,代碼來源:MatchOpTest.java

示例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));
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:13,代碼來源:MatchOpTest.java

示例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));
}
 
開發者ID:xapn,項目名稱:test-as-you-think,代碼行數:8,代碼來源:ResultOfEventTest.java

示例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;
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:16,代碼來源:RangeOfDoubles.java

示例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;
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:9,代碼來源:JCacheBasedDoublePredicateMemoizer.java

示例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.");
}
 
開發者ID:sebhoss,項目名稱:memoization.java,代碼行數:11,代碼來源:ConcurrentMapBasedDoublePredicateMemoizer.java


注:本文中的java.util.function.DoublePredicate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。