Predicate.java official document translation

package java.util.function;

import java.util.Objects;

/** *
Represents a predicate (boolean-valued function) of one
argument . <a href="package-summary.html">Functional interface</a> * Its functional method is {@link #test(Object)}. * * @param <T> the type of the input to the predicate * * @since 1.8 */ @FunctionalInterface public interface Predicate<T> {     /**      * Evaluate this predicate on the given argument      *      * @param t the input argument      * @return {@code true} if the input argument matches the predicate,      * otherwise {@code false}

















     */
    boolean test(T t);

    /**
     * Returns a predicate that represents the logical AND of one predicate short-circuited with another predicate.
     * When evaluating a combined predicate, if the first predicate is {@code false},
     * then the second {@code other} will not execute.
     *
     *
     * Any exception thrown while evaluating any predicate is passed to the caller, if
     * evaluation of that predicate throws an exception, no other {@code other} predicate will be evaluated.
     *
     * @param other a predicate that will be logically-ANDed with this
     * predicate
     * @return a composed predicate that represents the short-circuiting logical
     * AND of this predicate and the {@code other} predicate
     * @throws NullPointerException if other is null
     */
    default Predicate<T> and(Predicate<? super T> other) {
        Objects.requireNonNull(other);
        return (t) -> test(t) && other.test(t);
    }

    /**
     * Returns a predicate. Represents the logical negation of this predicate
     *
     * @return a predicate that represents the logical negation of this
     * predicate
     */
    default Predicate<T> negate() {
        return (t) -> !test(t);
    }

    /**
       * return A predicate that represents the logical OR of a predicate short-circuited with another predicate.
     * When evaluating a combined predicate, if the first predicate is {@code false},
     * then the second {@code other} will not execute.
     **
     _
     * Any exception thrown while evaluating any predicate is passed to the caller, if
     * evaluation of that predicate throws an exception, no other {@code other} predicate will be evaluated.
     *
     * @param other a predicate that will be logically-ORed with this
     * predicate
     * @return a composed predicate that represents the short-circuiting logical
     * OR of this predicate and the {@code other} predicate
     * @throws NullPointerException if other is null
     */
    default Predicate<T> or(Predicate<? super T> other) {
        Objects.requireNonNull(other);
        return (t) -> test(t) || other.test(t);
    }

    /**
     * Returns a predicate that tests whether the two parameters are equal to pass
     *  {@link Objects#equals(Object, Object)}.
     *
     * @param <T> the type of arguments to the predicate
     * @param targetRef the object reference with which to compare for equality,
     *               which may be {@code null}
     * @return a predicate that tests if two arguments are equal according
     * to {@link Objects#equals(Object, Object)}
     */
    static <T> Predicate<T> isEqual(Object targetRef) {
        return (null == targetRef)
                ? Objects::isNull
                : object -> targetRef.equals(object);
    }
}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326636588&siteId=291194637