public final class Predicates extends Object
Predicate
instances.
All methods returns serializable predicates as long as they're given serializable parameters.
See the Guava User Guide article on the
use of Predicate
.
Modifier and Type | Method and Description |
---|---|
static <T> Predicate<T> |
alwaysTrue()
Returns a predicate that always evaluates to
true . |
static <A,B> Predicate<A> |
compose(Predicate<B> predicate,
Function<A,? extends B> function)
Returns the composition of a function and a predicate.
|
static <T> Predicate<T> |
equalTo(T target)
Returns a predicate that evaluates to
true if the object being
tested equals() the given target or both are null. |
static <T> Predicate<T> |
in(Collection<? extends T> target)
Returns a predicate that evaluates to
true if the object reference
being tested is a member of the given collection. |
static <T> Predicate<T> |
not(Predicate<T> predicate)
Returns a predicate that evaluates to
true if the given predicate
evaluates to false . |
public static <T> Predicate<T> alwaysTrue()
true
.public static <T> Predicate<T> not(Predicate<T> predicate)
true
if the given predicate
evaluates to false
.public static <T> Predicate<T> equalTo(T target)
true
if the object being
tested equals()
the given target or both are null.public static <T> Predicate<T> in(Collection<? extends T> target)
true
if the object reference
being tested is a member of the given collection. It does not defensively
copy the collection passed in, so future changes to it will alter the
behavior of the predicate.
This method can technically accept any Collection<?>
, but using
a typed collection helps prevent bugs. This approach doesn't block any
potential users since it is always possible to use Predicates.<Object>in()
.
target
- the collection that may contain the function inputCopyright © 2007-2024, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.