@Override public int indexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); if (fromIndex < 0) { fromIndex = 0; } else if (fromIndex >= this.byteBuf.writerIndex()) { return -1; } int length = this.byteBuf.writerIndex() - fromIndex; return this.byteBuf.forEachByte(fromIndex, length, predicate.negate()::test); }
@Override public int lastIndexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); if (fromIndex < 0) { return -1; } fromIndex = Math.min(fromIndex, this.byteBuf.writerIndex() - 1); return this.byteBuf.forEachByteDesc(0, fromIndex + 1, predicate.negate()::test); }
@Override public int indexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); if (fromIndex < 0) { fromIndex = 0; } else if (fromIndex >= this.byteBuf.writerIndex()) { return -1; } int length = this.byteBuf.writerIndex() - fromIndex; return this.byteBuf.forEachByte(fromIndex, length, predicate.negate()::test); }
@Override public int lastIndexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); if (fromIndex < 0) { return -1; } fromIndex = Math.min(fromIndex, this.byteBuf.writerIndex() - 1); return this.byteBuf.forEachByteDesc(0, fromIndex + 1, predicate.negate()::test); }
@Override public boolean anyMatch(IntPredicate predicate) { return next(predicate.negate()); }
/** * Creates a new instance of CharTokenizer with the supplied attribute factory using a custom predicate. * The predicate should return {@code true} for all valid token separator characters. * This factory also takes a function to normalize chars, e.g., lowercasing them, supplied as method reference or lambda expression. * <p> * This factory is intended to be used with lambdas or method references. E.g., an elegant way * to create an instance which behaves exactly as {@link WhitespaceTokenizer} and {@link LowerCaseFilter} is: * <pre class="prettyprint lang-java"> * Tokenizer tok = CharTokenizer.fromSeparatorCharPredicate(factory, Character::isWhitespace, Character::toLowerCase); * </pre> * * @deprecated Normalization should be done in a subsequent TokenFilter */ @Deprecated public static CharTokenizer fromSeparatorCharPredicate(AttributeFactory factory, final IntPredicate separatorCharPredicate, final IntUnaryOperator normalizer) { return fromTokenCharPredicate(factory, separatorCharPredicate.negate(), normalizer); }
IntPredicate predicate=i -> i==5; if(ints.length>0 && predicate.test(ints[0])) predicate=predicate.negate(); boolean result = IntStream.of(ints).anyMatch(predicate);
@Override public int lastIndexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "'predicate' must not be null"); if (fromIndex < 0) { return -1; } fromIndex = Math.min(fromIndex, this.byteBuf.writerIndex() - 1); return this.byteBuf.forEachByteDesc(0, fromIndex + 1, predicate.negate()::test); }
@Override public int indexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "'predicate' must not be null"); if (fromIndex < 0) { fromIndex = 0; } else if (fromIndex >= this.byteBuf.writerIndex()) { return -1; } int length = this.byteBuf.writerIndex() - fromIndex; return this.byteBuf.forEachByte(fromIndex, length, predicate.negate()::test); }
@Override public int lastIndexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); if (fromIndex < 0) { return -1; } fromIndex = Math.min(fromIndex, this.byteBuf.writerIndex() - 1); return this.byteBuf.forEachByteDesc(0, fromIndex + 1, predicate.negate()::test); }
@Override public int indexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "IntPredicate must not be null"); if (fromIndex < 0) { fromIndex = 0; } else if (fromIndex >= this.byteBuf.writerIndex()) { return -1; } int length = this.byteBuf.writerIndex() - fromIndex; return this.byteBuf.forEachByte(fromIndex, length, predicate.negate()::test); }
/** * Returns a stream consisting of the elements of this stream that don't * match the given predicate. * * <p> * This is an intermediate operation. * * @param predicate a non-interfering, stateless predicate to apply to each * element to determine if it should be excluded * @return the new stream */ public IntStreamEx remove(IntPredicate predicate) { return filter(predicate.negate()); }
IntPredicate dividesBy3 = i -> i % 3 == 0; IntPredicate dividesBy5 = i -> i % 5 == 0; IntPredicate doesntDivide = dividesBy3.negate().and(dividesBy5.negate()); IntStream.rangeClosed(0, 100).forEach(i -> { StringBuffer bfr = new StringBuffer(); if (dividesBy3.test(i)) bfr.append("Fizz"); if (dividesBy5.test(i)) bfr.append("Buzz"); if (doesntDivide.test(i)) bfr.append(i); System.out.println(bfr); });
static Matcher contains(Term term, IntPredicate predicate) { return (string, start) -> { Optional<MatchRegion> prefix = star(predicate.negate()).match(string, start); int actualStart = prefix.get().end; return term.match(string, actualStart); }; }
predicate = predicate.negate();