當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。