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


Java IntPredicate类代码示例

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


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

示例1: IntPredicate

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

示例2: makeInt

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

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

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

示例3: filter

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

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

示例4: takeIntWhile

import java.util.function.IntPredicate; //导入依赖的package包/类
/**
 * Adapted from StackOverflow {@linkplain so http://stackoverflow.com/questions/20746429/limit-a-stream-by-a-predicate}
 *
 * @param splitr the original Spliterator
 * @param predicate the predicate
 * @return a Spliterator.OfInt
 */
private static Spliterator.OfInt takeIntWhile(Spliterator.OfInt splitr, IntPredicate predicate) {
    return new Spliterators.AbstractIntSpliterator(splitr.estimateSize(), 0) {
        boolean stillGoing = true;

        @Override
        public boolean tryAdvance(IntConsumer consumer) {
            if (stillGoing) {
                boolean hadNext = splitr.tryAdvance((int elem) -> {
                    if (predicate.test(elem)) {
                        consumer.accept(elem);
                    } else {
                        stillGoing = false;
                    }
                });
                return hadNext && stillGoing;
            }
            return false;
        }
    };
}
 
开发者ID:fralalonde,项目名称:iostream,代码行数:28,代码来源:StreamInputAdapter.java

示例5: estimateSize

import java.util.function.IntPredicate; //导入依赖的package包/类
/**
 * Estimates the size of a filter applied to an IMembershipSet
 * @return an approximation of the size based on sampling. May return 0.
 * There are no strict guarantees on the quality of the approximation,
 * but is good enough for initialization of a hash table sizes.
 */
public static int estimateSize(final IMembershipSet baseMap,
                               final IntPredicate filter) {
    final IMembershipSet sampleSet = baseMap.sample(sizeEstimationSampleSize, 0);
    if (sampleSet.getSize() == 0)
        return 0;
    int eSize = 0;
    final IRowIterator iter = sampleSet.getIterator();
    int curr = iter.getNextRow();
    while (curr >= 0) {
        if (filter.test(curr))
            eSize++;
        curr = iter.getNextRow();
    }
    return (baseMap.getSize() * eSize) / sampleSet.getSize();
}
 
开发者ID:vmware,项目名称:hillview,代码行数:22,代码来源:MembershipSetFactory.java

示例6: shouldWrapExecutionExceptionInMemoizationException

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

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

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

示例7: shouldRequireNonNullPredicate

import java.util.function.IntPredicate; //导入依赖的package包/类
/**
*
*/
@Test
@SuppressWarnings(CompilerWarnings.UNUSED)
public void shouldRequireNonNullPredicate() {
    // given
    final ConcurrentMap<Integer, Boolean> cache = new ConcurrentHashMap<>();
    final IntPredicate predicate = null;
    final IntFunction<Integer> keyFunction = Integer::valueOf;

    // when
    thrown.expect(NullPointerException.class);
    thrown.expectMessage("Cannot memoize a NULL Predicate - provide an actual Predicate to fix this.");

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

示例8: shouldTestGivenValue

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

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

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

示例9: scanAllVersion

import java.util.function.IntPredicate; //导入依赖的package包/类
void scanAllVersion(IntPredicate predicate) {
    SkipListScanner scanner = this.slist.scan(0, true, 0, true);
    if (scanner == null) {
        return;
    }
    while (scanner.next()) {
        long pHead = scanner.getValuePointer();
        if (pHead == 0) {
            continue;
        }
        int oHead = Unsafe.getInt(pHead);
        if (oHead == 0) {
            continue;
        }
        for (ListNode i=ListNode.create(this.base, oHead); i!=null; i=i.getNextNode()) {
            boolean cont = predicate.test(i.getOffset());
            if (!cont) {
                return;
            }
        }
    }
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:23,代码来源:MemTablet.java

示例10: assertIntPredicates

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

import java.util.function.IntPredicate; //导入依赖的package包/类
@Test(dataProvider = "IntStreamTestData", dataProviderClass = IntStreamTestDataProvider.class)
public void testIntStream(String name, TestData.OfInt data) {
    for (IntPredicate p : INT_PREDICATES) {
        setContext("p", p);
        for (Kind kind : Kind.values()) {
            setContext("kind", kind);
            exerciseTerminalOps(data, intKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(ipFalse), intKinds.get(kind).apply(p));
            exerciseTerminalOps(data, s -> s.filter(ipEven), intKinds.get(kind).apply(p));
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:13,代码来源:MatchOpTest.java

示例12: checkAndSetOrder

import java.util.function.IntPredicate; //导入依赖的package包/类
private void checkAndSetOrder(IntPredicate expectedValue,
                              IntUnaryOperator newValue) {
    if (!expectedValue.test(invocationOrder)) {
        throw new TestSupport.AssertionFailedException(
                expectedValue + " -> " + newValue);
    }
    invocationOrder = newValue.applyAsInt(invocationOrder);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:ReaderTest.java

示例13: should_verify_an_actual_int_predicate_is_conform_to_an_expected_result

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

示例14: RangeOfInts

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

示例15: filterNumbersWithPredicate

import java.util.function.IntPredicate; //导入依赖的package包/类
public List<Integer> filterNumbersWithPredicate(final List<Integer> numbers,
    IntPredicate predicate) {
    List<Integer> filteredNumbers = new ArrayList<>();
    for (Integer number : numbers) {
        if (predicate.test(number)) {
            filteredNumbers.add(number);
        }
    }
    return filteredNumbers; 
}
 
开发者ID:PacktPublishing,项目名称:Java-9-with-JShell,代码行数:11,代码来源:example12_02.java


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