src/share/classes/java/util/function/Predicate.java

Print this page
rev 7047 : 8004015: Additional static and instance utils for functional interfaces.
Reviewed-by: briangoetz

*** 41,100 **** * * @param t the input object * @return {@code true} if the input object matches some criteria, otherwise * {@code false} */ ! public boolean test(T t); /** * Returns a predicate which evaluates to {@code true} only if this * predicate and the provided predicate both evaluate to {@code true}. If * this predicate returns {@code false} then the remaining predicate is not * evaluated. * ! * @param p a predicate which will be logically-ANDed with this predicate. * @return a new predicate which returns {@code true} only if both ! * predicates return {@code true}. */ ! public default Predicate<T> and(Predicate<? super T> p) { Objects.requireNonNull(p); return (t) -> test(t) && p.test(t); } /** * Returns a predicate which negates the result of this predicate. * * @return a new predicate who's result is always the opposite of this * predicate. */ ! public default Predicate<T> negate() { return (t) -> !test(t); } /** * Returns a predicate which evaluates to {@code true} if either this * predicate or the provided predicate evaluates to {@code true}. If this * predicate returns {@code true} then the remaining predicate is not * evaluated. * ! * @param p a predicate which will be logically-ORed with this predicate. * @return a new predicate which returns {@code true} if either predicate ! * returns {@code true}. */ ! public default Predicate<T> or(Predicate<? super T> p) { Objects.requireNonNull(p); return (t) -> test(t) || p.test(t); } /** ! * Returns a predicate that evaluates to {@code true} if both or neither of ! * the component predicates evaluate to {@code true}. * ! * @param p a predicate which will be logically-XORed with this predicte. ! * @return a predicate that evaluates to {@code true} if both or neither of ! * the component predicates evaluate to {@code true}. */ ! public default Predicate<T> xor(Predicate<? super T> p) { ! Objects.requireNonNull(p); ! return (t) -> test(t) ^ p.test(t); } } --- 41,104 ---- * * @param t the input object * @return {@code true} if the input object matches some criteria, otherwise * {@code false} */ ! boolean test(T t); /** * Returns a predicate which evaluates to {@code true} only if this * predicate and the provided predicate both evaluate to {@code true}. If * this predicate returns {@code false} then the remaining predicate is not * evaluated. * ! * @param p a predicate which will be logically-ANDed with this predicate * @return a new predicate which returns {@code true} only if both ! * predicates return {@code true} ! * @throws NullPointerException if p is null */ ! default Predicate<T> and(Predicate<? super T> p) { Objects.requireNonNull(p); return (t) -> test(t) && p.test(t); } /** * Returns a predicate which negates the result of this predicate. * * @return a new predicate who's result is always the opposite of this * predicate. */ ! default Predicate<T> negate() { return (t) -> !test(t); } /** * Returns a predicate which evaluates to {@code true} if either this * predicate or the provided predicate evaluates to {@code true}. If this * predicate returns {@code true} then the remaining predicate is not * evaluated. * ! * @param p a predicate which will be logically-ORed with this predicate * @return a new predicate which returns {@code true} if either predicate ! * returns {@code true} ! * @throws NullPointerException if p is null */ ! default Predicate<T> or(Predicate<? super T> p) { Objects.requireNonNull(p); return (t) -> test(t) || p.test(t); } /** ! * Returns a predicate who's result matches ! * {@code Objects.equals(target, t)}. * ! * @param <T> the type of values evaluated by the predicate ! * @param target the target value to be compared for equality ! * @return a predicate who's result matches ! * {@code Objects.equals(target, t)} */ ! static <T> Predicate<T> isEqual(Object target) { ! return (null == target) ! ? Objects::isNull ! : object -> target.equals(object); } }