/** * * @param file * File to travers the children. If this is null or a file instead of a directory, the predicate will never be called. * @param stopEarlyPredicate * This predicate is called for all children and hence can be used to traverse the children. If the predicate returns true, the iteration is stopped early. */ public static void iterateChildrenEarlyStopping(File file, Predicate<File> stopEarlyPredicate) { if (file == null || !file.isDirectory()) { return; } File[] files = file.listFiles(); if (files != null) { for (File child : files) { if (stopEarlyPredicate.test(child)) { return; } } } }
/** * Returns a predicate that represents the logical negation of the {@code this_} * predicate. * @param <T> the type of the input to the predicate * @param this_ the predicate to be negated * @return a predicate that represents the logical negation of the {@code this_} * predicate * @throws NullPointerException if {@code this_} is null */ public static <T> Predicate<T> negate(Predicate<? super T> this_) { Objects.requireNonNull(this_); return (t) -> !this_.test(t); }
/** * Returns a predicate that represents the logical negation of the {@code this_} * predicate. * @param <T> the type of the input to the predicate * @param this_ the predicate to be negated * @return a predicate that represents the logical negation of the {@code this_} * predicate * @throws NullPointerException if {@code this_} is null */ public static <T> Predicate<T> negate(Predicate<? super T> this_) { Objects.requireNonNull(this_); return (t) -> !this_.test(t); }
/** * Returns a composed predicate that represents a short-circuiting logical * OR of the {@code this_} predicate and another. When evaluating the composed * predicate, if the {@code this_} predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of the {@code this_} predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param <T> the type of the input to the predicates * @param this_ a predicate that will be logically-ORed with the {@code other} predicate * @param other a predicate that will be logically-ORed with the {@code this_} * predicate * @return a composed predicate that represents the short-circuiting logical * OR of the {@code this_} predicate and the {@code other} predicate * @throws NullPointerException if {@code this_} is null * @throws NullPointerException if other is null */ public static <T> Predicate<T> or(Predicate<? super T> this_, Predicate<? super T> other) { Objects.requireNonNull(this_); Objects.requireNonNull(other); return (t) -> this_.test(t) || other.test(t); }
/** * Returns a composed predicate that represents a short-circuiting logical * AND of the {@code this_} predicate and another. When evaluating the composed * predicate, if the {@code this_} predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of the {@code this_} predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param <T> the type of the input to the predicates * @param this_ a predicate that will be logically-ANDed with the {@code other} predicate * @param other a predicate that will be logically-ANDed with the {@code this_} * predicate * @return a composed predicate that represents the short-circuiting logical * AND of the {@code this_} predicate and the {@code other} predicate * @throws NullPointerException if {@code this_} is null * @throws NullPointerException if other is null */ public static <T> Predicate<T> and(Predicate<? super T> this_, Predicate<? super T> other) { Objects.requireNonNull(this_); Objects.requireNonNull(other); return (t) -> this_.test(t) && other.test(t); }
/** * Returns a composed predicate that represents a short-circuiting logical * OR of the {@code this_} predicate and another. When evaluating the composed * predicate, if the {@code this_} predicate is {@code true}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of the {@code this_} predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param <T> the type of the input to the predicates * @param this_ a predicate that will be logically-ORed with the {@code other} predicate * @param other a predicate that will be logically-ORed with the {@code this_} * predicate * @return a composed predicate that represents the short-circuiting logical * OR of the {@code this_} predicate and the {@code other} predicate * @throws NullPointerException if {@code this_} is null * @throws NullPointerException if other is null */ public static <T> Predicate<T> or(Predicate<? super T> this_, Predicate<? super T> other) { Objects.requireNonNull(this_); Objects.requireNonNull(other); return (t) -> this_.test(t) || other.test(t); }
/** * Returns a composed predicate that represents a short-circuiting logical * AND of the {@code this_} predicate and another. When evaluating the composed * predicate, if the {@code this_} predicate is {@code false}, then the {@code other} * predicate is not evaluated. * * <p>Any exceptions thrown during evaluation of either predicate are relayed * to the caller; if evaluation of the {@code this_} predicate throws an exception, the * {@code other} predicate will not be evaluated. * * @param <T> the type of the input to the predicates * @param this_ a predicate that will be logically-ANDed with the {@code other} predicate * @param other a predicate that will be logically-ANDed with the {@code this_} * predicate * @return a composed predicate that represents the short-circuiting logical * AND of the {@code this_} predicate and the {@code other} predicate * @throws NullPointerException if {@code this_} is null * @throws NullPointerException if other is null */ public static <T> Predicate<T> and(Predicate<? super T> this_, Predicate<? super T> other) { Objects.requireNonNull(this_); Objects.requireNonNull(other); return (t) -> this_.test(t) && other.test(t); }
Iterator<T> each = (Iterator<T>) it.iterator(); while (each.hasNext()) { if (filter.test(each.next())) { each.remove(); removed = true;
private T getObjectCloseTo(ShortPoint2D position, Predicate<T> acceptor) { int bestDistance = Integer.MAX_VALUE; T currBest = null; for (T currEntry : data) { if (acceptor != null && !acceptor.test(currEntry)) { continue; } int currDist = MathUtils.squareHypot(position, currEntry.getPosition()); if (bestDistance > currDist) { bestDistance = currDist; currBest = currEntry; } } return currBest; } }
Iterator<T> each = (Iterator<T>) it.iterator(); while (each.hasNext()) { if (filter.test(each.next())) { each.remove(); removed = true;
@Override public boolean tryAdvance(Consumer<? super T> action) { boolean test = true; if (takeOrDrop && // If can take checkCancelOnCount() && // and if not cancelled s.tryAdvance(this) && // and if advanced one element (test = p.test(t))) { // and test on element passes action.accept(t); // then accept element return true; } else { // Taking is finished takeOrDrop = false; // Cancel all further traversal and splitting operations // only if test of element failed (short-circuited) if (!test) cancel.set(true); return false; } }
@Override public boolean tryAdvance(Consumer<? super T> action) { boolean test = true; if (takeOrDrop && // If can take checkCancelOnCount() && // and if not cancelled s.tryAdvance(this) && // and if advanced one element (test = p.test(t))) { // and test on element passes action.accept(t); // then accept element return true; } else { // Taking is finished takeOrDrop = false; // Cancel all further traversal and splitting operations // only if test of element failed (short-circuited) if (!test) cancel.set(true); return false; } }
/** * If a value is present, and the value matches the given predicate, * returns an {@code Optional} describing the value, otherwise returns an * empty {@code Optional}. * * @param predicate the predicate to apply to the value, if present * @return an {@code Optional} describing the value of this {@code Optional}, * if a value is present and the value matches the given predicate, * otherwise an empty {@code Optional} * @throws NullPointerException if the predicate is {@code null} */ public Optional<T> filter(Predicate<? super T> predicate) { Objects.requireNonNull(predicate); if (!isPresent()) { return this; } else { return predicate.test(value) ? this : empty(); } }
/** * If a value is present, and the value matches the given predicate, * returns an {@code Optional} describing the value, otherwise returns an * empty {@code Optional}. * * @param predicate the predicate to apply to the value, if present * @return an {@code Optional} describing the value of this {@code Optional}, * if a value is present and the value matches the given predicate, * otherwise an empty {@code Optional} * @throws NullPointerException if the predicate is {@code null} */ public Optional<T> filter(Predicate<? super T> predicate) { Objects.requireNonNull(predicate); if (!isPresent()) { return this; } else { return predicate.test(value) ? this : empty(); } }
@Override public boolean tryAdvance(Consumer<? super T> action) { if (takeOrDrop) { takeOrDrop = false; boolean adv; boolean dropped = false; while ((adv = s.tryAdvance(this)) && // If advanced one element checkCancelOnCount() && // and if not cancelled p.test(t)) { // and test on element passes dropped = true; // then drop element } // Report advanced element, if any if (adv) { // Cancel all further dropping if one or more elements // were previously dropped if (dropped) cancel.set(true); action.accept(t); } return adv; } else { return s.tryAdvance(action); } }
@Override public boolean tryAdvance(Consumer<? super T> action) { if (takeOrDrop) { takeOrDrop = false; boolean adv; boolean dropped = false; while ((adv = s.tryAdvance(this)) && // If advanced one element checkCancelOnCount() && // and if not cancelled p.test(t)) { // and test on element passes dropped = true; // then drop element } // Report advanced element, if any if (adv) { // Cancel all further dropping if one or more elements // were previously dropped if (dropped) cancel.set(true); action.accept(t); } return adv; } else { return s.tryAdvance(action); } }
@Override public void onCompletion(CountedCompleter<?> caller) { if (mustFindFirst) { for (FindTask<P_IN, P_OUT, O> child = leftChild, p = null; child != p; p = child, child = rightChild) { O result = child.getLocalResult(); if (result != null && op.presentPredicate.test(result)) { setLocalResult(result); foundResult(result); break; } } } super.onCompletion(caller); } }
@Override public void onCompletion(CountedCompleter<?> caller) { if (mustFindFirst) { for (FindTask<P_IN, P_OUT, O> child = leftChild, p = null; child != p; p = child, child = rightChild) { O result = child.getLocalResult(); if (result != null && op.presentPredicate.test(result)) { setLocalResult(result); foundResult(result); break; } } } super.onCompletion(caller); } }
return new CollectorImpl<>(downstream.supplier(), (r, t) -> { if (predicate.test(t)) { downstreamAccumulator.accept(r, t);
BiConsumer<A, ? super T> downstreamAccumulator = downstream.accumulator(); BiConsumer<Partition<A>, T> accumulator = (result, t) -> downstreamAccumulator.accept(predicate.test(t) ? result.forTrue : result.forFalse, t); BinaryOperator<A> op = downstream.combiner(); BinaryOperator<Partition<A>> merger = (left, right) ->