java.util.function.IntPredicate Java Examples
The following examples show how to use
java.util.function.IntPredicate.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: IntPipeline.java From desugar_jdk_libs with GNU General Public License v2.0 | 6 votes |
@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); } }; } }; }
Example #2
Source File: MatchOps.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example #3
Source File: IntPipeline.java From jdk1.8-source-analysis with Apache License 2.0 | 6 votes |
@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); } }; } }; }
Example #4
Source File: MatchOps.java From Bytecoder with Apache License 2.0 | 6 votes |
/** * 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); }
Example #5
Source File: IntPipeline.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
@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); } }; } }; }
Example #6
Source File: MnemonicHelper.java From consulo with Apache License 2.0 | 6 votes |
public static boolean hasMnemonic(@Nullable Component component, int keyCode) { if (component instanceof AbstractButton) { AbstractButton button = (AbstractButton)component; if (button instanceof JBOptionButton) { return ((JBOptionButton)button).isOkToProcessDefaultMnemonics() || button.getMnemonic() == keyCode; } else { return button.getMnemonic() == keyCode; } } if (component instanceof JLabel) { return ((JLabel)component).getDisplayedMnemonic() == keyCode; } IntPredicate checker = UIUtil.getClientProperty(component, MNEMONIC_CHECKER); return checker != null && checker.test(keyCode); }
Example #7
Source File: Common_hash_support.java From uima-uimaj with Apache License 2.0 | 6 votes |
/** * This method calls the subclass's copy_to_new_table method, * passing an inner lambda containing common code for copying old to new. * * That inner lambda, when invoked by the copy_to_new_table method, * is passed another lambda of one argument (the old index) * which is called to copy each element. * @param new_capacity * @param old_capacity */ private void copyOld2New(int new_capacity, int old_capacity) { copy_to_new_table( new_capacity, old_capacity, // this code assigned to "commonCopy" arg (IntConsumer copyToNew, IntPredicate is_valid_old_key) -> { newTable(new_capacity); removed = 0; // reset before put, otherwise, causes premature expansion for (int i = 0; i < old_capacity; i++) { if (is_valid_old_key.test(i)) { copyToNew.accept(i); } } }); }
Example #8
Source File: UriEncoding.java From ditto with Eclipse Public License 2.0 | 6 votes |
private static byte[] encodeBytes(final byte[] source, final IntPredicate allowedChars) { requireNonNull(source); requireNonNull(allowedChars); final ByteArrayOutputStream out = new ByteArrayOutputStream(source.length); for (byte b : source) { if (b < 0) { b += 256; } if (allowedChars.test((char) b)) { out.write(b); } else { out.write('%'); final char hex1 = Character.toUpperCase(Character.forDigit((b >> 4) & 0xF, 16)); final char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16)); out.write(hex1); out.write(hex2); } } return out.toByteArray(); }
Example #9
Source File: MatchOps.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example #10
Source File: Sliced.java From cactoos with MIT License | 5 votes |
/** * Constructor. * @param start Starting index * @param end Predicate that test whether iterating should stop * @param iterator Decorated iterator */ private Sliced(final int start, final IntPredicate end, final Iterator<T> iterator) { this.start = start; this.end = end; this.iterator = iterator; this.current = 0; }
Example #11
Source File: TakeDrop.java From streamex with Apache License 2.0 | 5 votes |
TDOfInt(Spliterator.OfInt source, boolean drop, boolean inclusive, IntPredicate predicate) { super(source.estimateSize(), source.characteristics() & (ORDERED | SORTED | CONCURRENT | IMMUTABLE | NONNULL | DISTINCT)); this.drop = drop; this.predicate = predicate; this.inclusive = inclusive; this.source = source; }
Example #12
Source File: MatchOpTest.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@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)); } } }
Example #13
Source File: ColumnIndexBuilder.java From parquet-mr with Apache License 2.0 | 5 votes |
@Override public <T extends Comparable<T>, U extends UserDefinedPredicate<T>> PrimitiveIterator.OfInt visit( UserDefined<T, U> udp) { final UserDefinedPredicate<T> predicate = udp.getUserDefinedPredicate(); final boolean acceptNulls = predicate.acceptsNullValue(); if (acceptNulls && nullCounts == null) { // Nulls match so if we don't have null related statistics we have to return all pages return IndexIterator.all(getPageCount()); } return IndexIterator.filter(getPageCount(), new IntPredicate() { private int arrayIndex = -1; @Override public boolean test(int pageIndex) { if (isNullPage(pageIndex)) { return acceptNulls; } else { ++arrayIndex; if (acceptNulls && nullCounts[pageIndex] > 0) { return true; } org.apache.parquet.filter2.predicate.Statistics<T> stats = createStats(arrayIndex); return !predicate.canDrop(stats); } } }); }
Example #14
Source File: FastFilters.java From RankSys with Mozilla Public License 2.0 | 5 votes |
/** * AND of two or more filters. * * @param <U> type of the users * @param filters a number of item filters * @return an item filter which does a logical AND to two or more filters */ @SuppressWarnings("unchecked") public static <U> Function<U, IntPredicate> and(Function<U, IntPredicate>... filters) { return user -> { IntPredicate andPredicate = iidx -> true; for (Function<U, IntPredicate> filter : filters) { andPredicate = andPredicate.and(filter.apply(user)); } return andPredicate; }; }
Example #15
Source File: DefaultDataBuffer.java From spring-analysis-note with MIT License | 5 votes |
@Override public int lastIndexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); int i = Math.min(fromIndex, this.writePosition - 1); for (; i >= 0; i--) { byte b = this.byteBuffer.get(i); if (predicate.test(b)) { return i; } } return -1; }
Example #16
Source File: MatchOpTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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()); } }
Example #17
Source File: SimpleUnicodeRegExpMatcher.java From es6draft with MIT License | 5 votes |
private static Term star(IntPredicate predicate) { return (string, start) -> { int i = start; while (i < string.length()) { int codePoint = string.codePointAt(i); if (predicate.test(codePoint)) { i += Character.charCount(codePoint); continue; } break; } return Optional.of(new MatchRegion(start, i)); }; }
Example #18
Source File: ArrayLengthQuery.java From crate with Apache License 2.0 | 5 votes |
NumTermsPerDocTwoPhaseIterator(LeafReader reader, IntUnaryOperator numTermsOfDoc, IntPredicate matches) { super(DocIdSetIterator.all(reader.maxDoc())); this.numTermsOfDoc = numTermsOfDoc; this.matches = matches; }
Example #19
Source File: IntPredicateTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testNegate() throws Exception { int arg = 5; IntPredicate alwaysTrue = x -> { assertEquals(x, arg); return true; }; assertFalse(alwaysTrue.negate().test(arg)); IntPredicate alwaysFalse = x -> { assertEquals(x, arg); return false; }; assertTrue(alwaysFalse.negate().test(arg)); }
Example #20
Source File: AbstractCodepointIterator.java From ph-commons with Apache License 2.0 | 5 votes |
@Nonnull public CodepointIteratorRestricted restrict (@Nonnull final IntPredicate aFilter, final boolean bScanning, final boolean bInvert) { return new CodepointIteratorRestricted (this, aFilter, bScanning, bInvert); }
Example #21
Source File: MatchOpTest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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()); } }
Example #22
Source File: MatchOpTest.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@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)); } } }
Example #23
Source File: Consumer.java From strimzi-kafka-operator with Apache License 2.0 | 5 votes |
Consumer(KafkaClientProperties properties, CompletableFuture<Integer> resultPromise, IntPredicate msgCntPredicate, String topic, String clientName) { super(resultPromise, msgCntPredicate); this.properties = properties; this.topic = topic; this.clientName = clientName; this.vertx = Vertx.vertx(); this.consumer = KafkaConsumer.create(vertx, properties.getProperties()); }
Example #24
Source File: PrimeTest.java From journaldev with MIT License | 5 votes |
private static boolean isPrime(int number) { IntPredicate isDivisible = index -> number % index == 0; return number > 1 && IntStream.range(2, number - 1).noneMatch( isDivisible); }
Example #25
Source File: IntPipeline.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
@Override public final boolean anyMatch(IntPredicate predicate) { return evaluate(MatchOps.makeInt(predicate, MatchOps.MatchKind.ANY)); }
Example #26
Source File: VerifyHelper.java From Launcher with GNU General Public License v3.0 | 4 votes |
public static IntPredicate range(int min, int max) { return i -> i >= min && i <= max; }
Example #27
Source File: AllOperator.java From crate with Apache License 2.0 | 4 votes |
public AllOperator(Signature signature, Signature boundSignature, IntPredicate cmp) { this.signature = signature; this.boundSignature = boundSignature; this.cmp = cmp; this.leftType = boundSignature.getArgumentDataTypes().get(0); }
Example #28
Source File: IntPipeline.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
@Override public final boolean noneMatch(IntPredicate predicate) { return evaluate(MatchOps.makeInt(predicate, MatchOps.MatchKind.NONE)); }
Example #29
Source File: TextResultSetHandler.java From Mycat2 with GNU General Public License v3.0 | 4 votes |
public TextResultSetHandler(ResultSetTransfor collector, IntPredicate predicate) { this.collector = collector; this.predicate = predicate; }
Example #30
Source File: MathUtil.java From Java-11-Cookbook-Second-Edition with MIT License | 4 votes |
private static Integer computeFirstNSum(Integer count, IntPredicate filter){ return IntStream.iterate(1,i -> i+1) .filter(filter) .limit(count).sum(); }