当前位置: 首页>>代码示例>>Java>>正文


Java LongPredicate类代码示例

本文整理汇总了Java中java.util.function.LongPredicate的典型用法代码示例。如果您正苦于以下问题:Java LongPredicate类的具体用法?Java LongPredicate怎么用?Java LongPredicate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


LongPredicate类属于java.util.function包,在下文中一共展示了LongPredicate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: LongPredicate

import java.util.function.LongPredicate; //导入依赖的package包/类
@Test
public void LongPredicate()
{
    // TODO - Convert the anonymous inner class to a lambda
    LongPredicate predicate = new LongPredicate()
    {
        @Override
        public boolean test(long value)
        {
            return value % 2 == 0;
        }
    };
    List<Long> evens =
            LongStream.rangeClosed(1, 5).filter(predicate).boxed().collect(Collectors.toList());
    Assert.assertEquals(Arrays.asList(2L, 4L), evens);
    List<Long> odds =
            LongStream.rangeClosed(1, 5).filter(predicate.negate()).boxed().collect(Collectors.toList());
    Assert.assertEquals(Arrays.asList(1L, 3L, 5L), odds);
    Assert.assertTrue(LongStream.rangeClosed(1, 5).anyMatch(predicate));
    Assert.assertFalse(LongStream.rangeClosed(1, 5).allMatch(predicate));
    Assert.assertFalse(LongStream.rangeClosed(1, 5).noneMatch(predicate));
}
 
开发者ID:BNYMellon,项目名称:CodeKatas,代码行数:23,代码来源:PrimitiveFunctionalInterfaceTest.java

示例2: filter

import java.util.function.LongPredicate; //导入依赖的package包/类
@Override
public final LongStream filter(LongPredicate predicate) {
    Objects.requireNonNull(predicate);
    return new StatelessOp<Long>(this, StreamShape.LONG_VALUE,
                                 StreamOpFlag.NOT_SIZED) {
        @Override
        Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
            return new Sink.ChainedLong<Long>(sink) {
                @Override
                public void begin(long size) {
                    downstream.begin(-1);
                }

                @Override
                public void accept(long t) {
                    if (predicate.test(t))
                        downstream.accept(t);
                }
            };
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:23,代码来源:LongPipeline.java

示例3: makeLong

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
 * Constructs a quantified predicate matcher for a {@code LongStream}.
 *
 * @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<Long, Boolean> makeLong(LongPredicate predicate,
                                                 MatchKind matchKind) {
    Objects.requireNonNull(predicate);
    Objects.requireNonNull(matchKind);
    class MatchSink extends BooleanTerminalSink<Long> implements Sink.OfLong {

        MatchSink() {
            super(matchKind);
        }

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

    return new MatchOp<>(StreamShape.LONG_VALUE, matchKind, MatchSink::new);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:30,代码来源:MatchOps.java

示例4: shouldRequireNonNullCache

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullCache() {
    // given
    final ConcurrentMap<Long, Boolean> cache = null;
    final LongPredicate predicate = input -> true;
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Provide an empty map instead of NULL.");

    // then
    new ConcurrentMapBasedLongPredicateMemoizer<>(cache, keyFunction, predicate);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:ConcurrentMapBasedLongPredicateMemoizerTest.java

示例5: shouldTestGivenValue

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldTestGivenValue() {
    // given
    final LongPredicate predicate = Mockito.mock(LongPredicate.class);
    final LongFunction<String> keyFunction = a -> "key";
    final Cache<String, Boolean> cache = CacheBuilder.newBuilder().build();

    // when
    final GuavaCacheBasedLongPredicateMemoizer<String> memoizer = new GuavaCacheBasedLongPredicateMemoizer<>(
            cache, keyFunction, predicate);

    // then
    memoizer.test(123);
    Mockito.verify(predicate).test(123);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:19,代码来源:GuavaCacheBasedLongPredicateMemoizerTest.java

示例6: shouldWrapExecutionExceptionInMemoizationException

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
 * @throws ExecutionException
 *             Added for the call to 'cache.get(..)'.
 */
@Test
@SuppressWarnings(CompilerWarnings.UNCHECKED)
public void shouldWrapExecutionExceptionInMemoizationException() throws ExecutionException {
    // given
    final LongPredicate predicate = a -> true;
    final LongFunction<String> keyFunction = a -> "key";
    final Cache<String, Boolean> cache = Mockito.mock(Cache.class);
    given(cache.get(any(), any())).willThrow(ExecutionException.class);
    final GuavaCacheBasedLongPredicateMemoizer<String> memoizer = new GuavaCacheBasedLongPredicateMemoizer<>(
            cache, keyFunction, predicate);

    // when
    thrown.expect(MemoizationException.class);

    // then
    memoizer.test(123);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:22,代码来源:GuavaCacheBasedLongPredicateMemoizerTest.java

示例7: assertLongPredicates

import java.util.function.LongPredicate; //导入依赖的package包/类
private void assertLongPredicates(Supplier<LongStream> source, Kind kind, LongPredicate[] predicates, boolean... answers) {
    for (int i = 0; i < predicates.length; i++) {
        setContext("i", i);
        boolean match = longKinds.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

示例8: testLongStream

import java.util.function.LongPredicate; //导入依赖的package包/类
@Test(dataProvider = "LongStreamTestData", dataProviderClass = LongStreamTestDataProvider.class)
public void testLongStream(String name, TestData.OfLong data) {
    for (LongPredicate p : LONG_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpFalse), longKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(lpEven), longKinds.get(kind).apply(p));
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:MatchOpTest.java

示例9: should_verify_an_actual_long_predicate_is_conform_to_an_expected_result

import java.util.function.LongPredicate; //导入依赖的package包/类
@Test
public void should_verify_an_actual_long_predicate_is_conform_to_an_expected_result() {
    assertThat(resultOf(() -> {
        gwtMock.whenAnEventHappensInRelationToAnActionOfTheConsumer();
        return (LongPredicate) number -> number < 100;
    }).accepts(99)).hasSameClassAs(assertThat((LongPredicate) t -> t == 0));
}
 
开发者ID:xapn,项目名称:test-as-you-think,代码行数:8,代码来源:ResultOfEventTest.java

示例10: RangeOfLongs

import java.util.function.LongPredicate; //导入依赖的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
 */
RangeOfLongs(long start, long end, long step, LongPredicate 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,代码来源:RangeOfLongs.java

示例11: thatReturnsOnCatch

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
 * @param defaultReturnValue A value to return if any throwable is caught.
 * @return An interface that returns a default value if any exception occurs.
 */
default LongPredicate thatReturnsOnCatch(final boolean defaultReturnValue) {
  return (final long v1) -> {
    try {
      return testWithThrowable(v1);
    } catch(final Throwable throwable) {
      return defaultReturnValue;
    }
  };
}
 
开发者ID:StefanLiebenberg,项目名称:throwable-interfaces,代码行数:14,代码来源:LongPredicateWithThrowable.java

示例12: shouldMemoizeLongPredicateWithKeyFunction

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongPredicateWithKeyFunction() {
    // given
    final LongPredicate predicate = a -> true;
    final LongFunction<String> keyFunction = a -> "key";

    // when
    final LongPredicate memoize = JCacheMemoize.longPredicate(predicate, keyFunction);

    // then
    Assert.assertNotNull("Memoized LongPredicate is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:16,代码来源:JCacheMemoizeCustomKeyTest.java

示例13: shouldMemoizePredicateCall

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizePredicateCall() {
    // given
    final ConcurrentMap<Long, Boolean> cache = new ConcurrentHashMap<>();
    final LongPredicate predicate = input -> true;
    final LongFunction<Long> keyFunction = Long::valueOf;

    // when
    final ConcurrentMapBasedLongPredicateMemoizer<Long> memoizer = new ConcurrentMapBasedLongPredicateMemoizer<>(
            cache, keyFunction, predicate);

    // then
    Assert.assertTrue("Memoized value does not match expectations", memoizer.test(123L));
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:18,代码来源:ConcurrentMapBasedLongPredicateMemoizerTest.java

示例14: shouldMemoizeLongPredicateWithLambda

import java.util.function.LongPredicate; //导入依赖的package包/类
/**
*
*/
@Test
public void shouldMemoizeLongPredicateWithLambda() {
    // given

    // when
    final LongPredicate memoize = JCacheMemoize.longPredicate(a -> true);

    // then
    Assert.assertNotNull("Memoized LongPredicate is NULL", memoize);
}
 
开发者ID:sebhoss,项目名称:memoization.java,代码行数:14,代码来源:JCacheMemoizeLambdaTest.java

示例15: ConcurrentMapBasedLongPredicateMemoizer

import java.util.function.LongPredicate; //导入依赖的package包/类
@SuppressWarnings(CompilerWarnings.NLS)
ConcurrentMapBasedLongPredicateMemoizer(
        final ConcurrentMap<KEY, Boolean> cache,
        final LongFunction<KEY> keyFunction,
        final LongPredicate 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,代码来源:ConcurrentMapBasedLongPredicateMemoizer.java


注:本文中的java.util.function.LongPredicate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。