public final class Predicates
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
Predicates.AlwaysFalsePredicate |
private static class |
Predicates.AlwaysTruePredicate |
private static class |
Predicates.AndPredicate<T> |
private static class |
Predicates.InPredicate<T> |
private static class |
Predicates.InstanceOfPredicate |
private static class |
Predicates.IsEqualToPredicate<T> |
private static class |
Predicates.IsNullPredicate |
private static class |
Predicates.NotNullPredicate |
private static class |
Predicates.NotPredicate<T> |
private static class |
Predicates.OrPredicate<T> |
Modifier | Constructor and Description |
---|---|
private |
Predicates() |
Modifier and Type | Method and Description |
---|---|
static <T> Predicate<T> |
alwaysFalse()
Returns a predicate that always evaluates to
false . |
static <T> Predicate<T> |
alwaysTrue()
Returns a predicate that always evaluates to
true . |
static <T> Predicate<T> |
and(java.util.Collection<? extends Predicate<? super T>> components)
Returns a predicate that evaluates to
true if each of its
components evaluates to true . |
static <T> Predicate<T> |
and(Predicate<? super T>... components)
Returns a predicate that evaluates to
true if each of its
components evaluates to true . |
static <T> Predicate<T> |
and(Predicate<? super T> first,
Predicate<? super T> second)
Returns a predicate that evaluates to
true if both of its
components evaluate to true . |
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(java.util.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 Predicate<java.lang.Object> |
instanceOf(java.lang.Class<?> clazz)
Returns a predicate that evaluates to
true if the object being
tested is an instance of the given class. |
static <T> Predicate<T> |
isNull()
Returns a predicate that evaluates to
true if the object reference
being tested is null. |
static <T> Predicate<T> |
not(Predicate<T> predicate)
Returns a predicate that evaluates to
true if the given predicate
evaluates to false . |
static <T> Predicate<T> |
notNull()
Returns a predicate that evaluates to
true if the object reference
being tested is not null. |
static <T> Predicate<T> |
or(java.util.Collection<? extends Predicate<? super T>> components)
Returns a predicate that evaluates to
true if any one of its
components evaluates to true . |
static <T> Predicate<T> |
or(Predicate<? super T>... components)
Returns a predicate that evaluates to
true if any one of its
components evaluates to true . |
static <T> Predicate<T> |
or(Predicate<? super T> first,
Predicate<? super T> second)
Returns a predicate that evaluates to
true if either of its
components evaluates to true . |
public static <T> Predicate<T> alwaysTrue()
true
.public static <T> Predicate<T> alwaysFalse()
false
.public static <T> Predicate<T> isNull()
true
if the object reference
being tested is null.public static <T> Predicate<T> notNull()
true
if the object reference
being tested is not null.public static <T> Predicate<T> not(Predicate<T> predicate)
true
if the given predicate
evaluates to false
.predicate
- the inner predicatepublic static <T> Predicate<T> and(java.util.Collection<? extends Predicate<? super T>> components)
true
if each of its
components evaluates to true
. The components are evaluated in
order, and evaluation will be "short-circuited" as soon as a false
predicate is found. It defensively copies the iterable passed in, so future
changes to it won't alter the behavior of this predicate. If components
is empty, the returned predicate will always evaluate to true
.components
- the componentspublic static <T> Predicate<T> and(Predicate<? super T>... components)
true
if each of its
components evaluates to true
. The components are evaluated in
order, and evaluation will be "short-circuited" as soon as a false
predicate is found. It defensively copies the array passed in, so future
changes to it won't alter the behavior of this predicate. If components
is empty, the returned predicate will always evaluate to true
.components
- the componentspublic static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T> second)
true
if both of its
components evaluate to true
. The components are evaluated in
order, and evaluation will be "short-circuited" as soon as a false
predicate is found.first
- the firstsecond
- the secondpublic static <T> Predicate<T> or(java.util.Collection<? extends Predicate<? super T>> components)
true
if any one of its
components evaluates to true
. The components are evaluated in
order, and evaluation will be "short-circuited" as soon as as soon as a
true predicate is found. It defensively copies the iterable passed in, so
future changes to it won't alter the behavior of this predicate. If components
is empty, the returned predicate will always evaluate to false
.components
- the componentspublic static <T> Predicate<T> or(Predicate<? super T>... components)
true
if any one of its
components evaluates to true
. The components are evaluated in
order, and evaluation will be "short-circuited" as soon as as soon as a
true predicate is found. It defensively copies the array passed in, so
future changes to it won't alter the behavior of this predicate. If components
is empty, the returned predicate will always evaluate to false
.components
- the componentspublic static <T> Predicate<T> or(Predicate<? super T> first, Predicate<? super T> second)
true
if either of its
components evaluates to true
. The components are evaluated in
order, and evaluation will be "short-circuited" as soon as as soon as a
true predicate is found.first
- the firstsecond
- the secondpublic static <T> Predicate<T> equalTo(T target)
true
if the object being
tested equals()
the given target or both are null.target
- the targetpublic static Predicate<java.lang.Object> instanceOf(java.lang.Class<?> clazz)
true
if the object being
tested is an instance of the given class. If the object being tested
is null
this predicate evaluates to false
.
clazz
- the clazzpublic static <T> Predicate<T> in(java.util.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 input