/** * Returns a composed {@link BiIntToFloatFunction} that first applies the {@code before} * predicates to its input, and then applies this function to the result. If evaluation of either * operation throws an exception, it is relayed to the caller of the composed operation. This * method is just convenience, to provide the ability to execute an operation which accepts {@code * int} input, before this primitive function is executed. * * @param before1 The first predicate to apply before this function is applied * @param before2 The second predicate to apply before this function is applied * @return A composed {@code BiIntToFloatFunction} that first applies the {@code before} * predicates to its input, and then applies this function to the result. * @throws NullPointerException If given argument is {@code null} * @implSpec The input argument of this method is a able to handle primitive values. In this case * this is {@code int}. */ @Nonnull default BiIntToFloatFunction composeFromInt( @Nonnull final IntPredicate before1, @Nonnull final IntPredicate before2) { Objects.requireNonNull(before1); Objects.requireNonNull(before2); return (value1, value2) -> applyAsFloat(before1.test(value1), before2.test(value2)); }
private void selectNuclideFilter(String key) { IntPredicate p = key.matches(" *") ? n -> true : _nuclideFilters.get(key); if (p == null) { p = createNuclideFilter(key); _nuclideFilters.put(key, p); _nuclideFilterNames.add(key); } final IntPredicate predicate = p; _currentNuclideFilterProperty.set(inventory -> predicate.test(inventory.nucid)); }
@Test public void count_vowels_in_string_java8() { IntPredicate vowel = new IntPredicate() { @Override public boolean test(int t) { return t == 'a' || t == 'e' || t == 'i' || t == 'o' || t == 'u' || t == 'A' || t == 'E' || t == 'I' || t == 'O' || t == 'U'; } }; String phrase = "Whack for my daddy-o. There's whiskey in the jar-o"; long consonantCount = phrase.chars().filter(vowel.negate()).count(); assertEquals(38, consonantCount); }
public int leesTotGeldig(IntPredicate controle, String boodschap) { System.out.println(boodschap); int getal = scanner.nextInt(); while (!controle.test(getal)) { System.out.println(boodschap); getal = scanner.nextInt(); } return getal; }
@Override public int lastIndexOf(IntPredicate predicate, int fromIndex) { Assert.notNull(predicate, "'predicate' 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; }
private IntPredicate createNuclideFilter(String spec) { IntPredicate predicate = null; String specs[] = spec.split(","); for (int i = 0; i < specs.length; i++) { Matcher matcher = pattern.matcher(specs[i]); if (matcher.find()) { if (!valid(matcher.group(1), matcher.group(3))) { // TODO: indicate an error log.error("Illegal filter"); return n -> true; // ignore the spec; } IntPredicate p; if (matcher.group(3) == null) { p = createPredicate(matcher.group(1)); } else { p = createPredicate(matcher.group(1), matcher.group(3)); } predicate = predicate == null ? p : predicate.or(p); } } return predicate; }
@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.writePosition) { return -1; } for (int i = fromIndex; i < this.writePosition; i++) { byte b = this.byteBuffer.get(i); if (predicate.test(b)) { return i; } } return -1; }