8050818: Predicate::not - provide an easier way to negate a predicate

Reviewed-by: chegar, dl, psandoz, forax, smarks, redestad
This commit is contained in:
Jim Laskey 2018-05-30 12:40:04 -03:00
parent 0084eebd36
commit e18f24a98e
2 changed files with 84 additions and 0 deletions

View file

@ -116,4 +116,20 @@ public interface Predicate<T> {
? Objects::isNull
: object -> targetRef.equals(object);
}
/**
* Returns a predicate that is the negation of the supplied predicate.
*
* @param <T> the type of arguments to the specified predicate
* @param target predicate to negate
*
* @return a predicate that negates the results of the supplied
* predicate
*
* @since 11
*/
@SuppressWarnings("unchecked")
static <T> Predicate<T> not(Predicate<? super T> target) {
return (Predicate<T>)target.negate();
}
}