--- old/src/share/classes/java/util/function/Predicate.java 2012-12-20 16:32:25.804521020 -0800 +++ new/src/share/classes/java/util/function/Predicate.java 2012-12-20 16:32:25.576521009 -0800 @@ -24,6 +24,8 @@ */ package java.util.function; +import java.util.Objects; + /** * Determines if the input object matches some criteria. * @@ -41,4 +43,54 @@ * {@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. + * + * @return a new predicate which returns {@code true} only if both + * predicates return {@code true}. + */ + public default Predicate and(Predicate p) { + Objects.requireNonNull(p); + return (T 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 negate() { + return (T 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. + * + * @return a new predicate which returns {@code true} if either predicate + * returns {@code true}. + */ + public default Predicate or(Predicate p) { + Objects.requireNonNull(p); + return (T t) -> test(t) || p.test(t); + } + + /** + * Returns a predicate that evaluates to {@code true} if all or none of the + * component predicates evaluate to {@code true}. + * + * @return a predicate that evaluates to {@code true} if all or none of the + * component predicates evaluate to {@code true} + */ + public default Predicate xor(Predicate p) { + Objects.requireNonNull(p); + return (T t) -> test(t) ^ p.test(t); + } }