public class PredicateUtils extends Object
PredicateUtils provides reference implementations and utilities
for the Predicate functor interface. The supplied predicates are:
| Modifier and Type | Method and Description |
|---|---|
static <T> Predicate<T> |
allPredicate(Collection<? extends Predicate<T>> predicates)
Create a new Predicate that returns true only if all of the specified
predicates are true.
|
static <T> Predicate<T> |
allPredicate(Predicate<? super T>... predicates)
Create a new Predicate that returns true only if all of the specified
predicates are true.
|
static <T> Predicate<T> |
andPredicate(Predicate<? super T> predicate1,
Predicate<? super T> predicate2)
Create a new Predicate that returns true only if both of the specified
predicates are true.
|
static <T> Predicate<T> |
anyPredicate(Collection<? extends Predicate<T>> predicates)
Create a new Predicate that returns true if any of the specified
predicates are true.
|
static <T> Predicate<T> |
anyPredicate(Predicate<? super T>... predicates)
Create a new Predicate that returns true if any of the specified
predicates are true.
|
static <T> Predicate<T> |
asPredicate(Transformer<? super T,Boolean> transformer)
Create a new Predicate that wraps a Transformer.
|
static <T> Predicate<T> |
eitherPredicate(Predicate<? super T> predicate1,
Predicate<? super T> predicate2)
Create a new Predicate that returns true if one, but not both, of the
specified predicates are true.
|
static <T> Predicate<T> |
equalPredicate(T value)
Creates a Predicate that checks if the input object is equal to the
specified object using equals().
|
static <T> Predicate<T> |
exceptionPredicate()
Gets a Predicate that always throws an exception.
|
static <T> Predicate<T> |
falsePredicate()
Gets a Predicate that always returns false.
|
static <T> Predicate<T> |
identityPredicate(T value)
Creates a Predicate that checks if the input object is equal to the
specified object by identity.
|
static Predicate<Object> |
instanceofPredicate(Class<?> type)
Creates a Predicate that checks if the object passed in is of
a particular type, using instanceof.
|
static <T> Predicate<T> |
invokerPredicate(String methodName)
Creates a Predicate that invokes a method on the input object.
|
static <T> Predicate<T> |
invokerPredicate(String methodName,
Class<?>[] paramTypes,
Object[] args)
Creates a Predicate that invokes a method on the input object.
|
static <T> Predicate<T> |
neitherPredicate(Predicate<? super T> predicate1,
Predicate<? super T> predicate2)
Create a new Predicate that returns true if neither of the specified
predicates are true.
|
static <T> Predicate<T> |
nonePredicate(Collection<? extends Predicate<T>> predicates)
Create a new Predicate that returns true if none of the specified
predicates are true.
|
static <T> Predicate<T> |
nonePredicate(Predicate<? super T>... predicates)
Create a new Predicate that returns true if none of the specified
predicates are true.
|
static <T> Predicate<T> |
notNullPredicate()
Gets a Predicate that checks if the input object passed in is not null.
|
static <T> Predicate<T> |
notPredicate(Predicate<? super T> predicate)
Create a new Predicate that returns true if the specified predicate
returns false and vice versa.
|
static <T> Predicate<T> |
nullIsExceptionPredicate(Predicate<? super T> predicate)
Gets a Predicate that throws an exception if the input object is null,
otherwise it calls the specified Predicate.
|
static <T> Predicate<T> |
nullIsFalsePredicate(Predicate<? super T> predicate)
Gets a Predicate that returns false if the input object is null, otherwise
it calls the specified Predicate.
|
static <T> Predicate<T> |
nullIsTruePredicate(Predicate<? super T> predicate)
Gets a Predicate that returns true if the input object is null, otherwise
it calls the specified Predicate.
|
static <T> Predicate<T> |
nullPredicate()
Gets a Predicate that checks if the input object passed in is null.
|
static <T> Predicate<T> |
onePredicate(Collection<Predicate<T>> predicates)
Create a new Predicate that returns true if only one of the specified
predicates are true.
|
static <T> Predicate<T> |
onePredicate(Predicate<? super T>... predicates)
Create a new Predicate that returns true if only one of the specified
predicates are true.
|
static <T> Predicate<T> |
orPredicate(Predicate<? super T> predicate1,
Predicate<? super T> predicate2)
Create a new Predicate that returns true if either of the specified
predicates are true.
|
static <T> Predicate<T> |
transformedPredicate(Transformer<? super T,? extends T> transformer,
Predicate<? super T> predicate)
Creates a predicate that transforms the input object before passing it
to the predicate.
|
static <T> Predicate<T> |
truePredicate()
Gets a Predicate that always returns true.
|
static <T> Predicate<T> |
uniquePredicate()
Creates a Predicate that returns true the first time an object is
encountered, and false if the same object is received
again.
|
public static <T> Predicate<T> exceptionPredicate()
T - the type that the predicate queriesExceptionPredicatepublic static <T> Predicate<T> truePredicate()
T - the type that the predicate queriesTruePredicatepublic static <T> Predicate<T> falsePredicate()
T - the type that the predicate queriesFalsePredicatepublic static <T> Predicate<T> nullPredicate()
T - the type that the predicate queriesNullPredicatepublic static <T> Predicate<T> notNullPredicate()
T - the type that the predicate queriesNotNullPredicatepublic static <T> Predicate<T> equalPredicate(T value)
T - the type that the predicate queriesvalue - the value to compare againstEqualPredicatepublic static <T> Predicate<T> identityPredicate(T value)
T - the type that the predicate queriesvalue - the value to compare againstIdentityPredicatepublic static Predicate<Object> instanceofPredicate(Class<?> type)
null input
object will return false.type - the type to check for, may not be nullIllegalArgumentException - if the class is nullInstanceofPredicatepublic static <T> Predicate<T> uniquePredicate()
null input object
is accepted and will return true the first time, and false subsequently
as well.T - the type that the predicate queriesUniquePredicatepublic static <T> Predicate<T> invokerPredicate(String methodName)
For example, PredicateUtils.invokerPredicate("isEmpty");
will call the isEmpty method on the input object to
determine the predicate result.
T - the type that the predicate queriesmethodName - the method name to call on the input object, may not be nullIllegalArgumentException - if the methodName is null.InvokerTransformer,
TransformerPredicatepublic static <T> Predicate<T> invokerPredicate(String methodName, Class<?>[] paramTypes, Object[] args)
For example, PredicateUtils.invokerPredicate("isEmpty");
will call the isEmpty method on the input object to
determine the predicate result.
T - the type that the predicate queriesmethodName - the method name to call on the input object, may not be nullparamTypes - the parameter typesargs - the argumentsIllegalArgumentException - if the method name is nullIllegalArgumentException - if the paramTypes and args don't matchInvokerTransformer,
TransformerPredicatepublic static <T> Predicate<T> andPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2)
T - the type that the predicate queriespredicate1 - the first predicate, may not be nullpredicate2 - the second predicate, may not be nulland predicateIllegalArgumentException - if either predicate is nullAndPredicatepublic static <T> Predicate<T> allPredicate(Predicate<? super T>... predicates)
T - the type that the predicate queriespredicates - an array of predicates to check, may not be nullall predicateIllegalArgumentException - if the predicates array is nullIllegalArgumentException - if any predicate in the array is nullAllPredicatepublic static <T> Predicate<T> allPredicate(Collection<? extends Predicate<T>> predicates)
T - the type that the predicate queriespredicates - a collection of predicates to check, may not be nullall predicateIllegalArgumentException - if the predicates collection is nullIllegalArgumentException - if any predicate in the collection is nullAllPredicatepublic static <T> Predicate<T> orPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2)
T - the type that the predicate queriespredicate1 - the first predicate, may not be nullpredicate2 - the second predicate, may not be nullor predicateIllegalArgumentException - if either predicate is nullOrPredicatepublic static <T> Predicate<T> anyPredicate(Predicate<? super T>... predicates)
T - the type that the predicate queriespredicates - an array of predicates to check, may not be nullany predicateIllegalArgumentException - if the predicates array is nullIllegalArgumentException - if any predicate in the array is nullAnyPredicatepublic static <T> Predicate<T> anyPredicate(Collection<? extends Predicate<T>> predicates)
T - the type that the predicate queriespredicates - a collection of predicates to check, may not be nullany predicateIllegalArgumentException - if the predicates collection is nullIllegalArgumentException - if any predicate in the collection is nullAnyPredicatepublic static <T> Predicate<T> eitherPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2)
T - the type that the predicate queriespredicate1 - the first predicate, may not be nullpredicate2 - the second predicate, may not be nulleither predicateIllegalArgumentException - if either predicate is nullOnePredicatepublic static <T> Predicate<T> onePredicate(Predicate<? super T>... predicates)
T - the type that the predicate queriespredicates - an array of predicates to check, may not be nullone predicateIllegalArgumentException - if the predicates array is nullIllegalArgumentException - if any predicate in the array is nullOnePredicatepublic static <T> Predicate<T> onePredicate(Collection<Predicate<T>> predicates)
T - the type that the predicate queriespredicates - a collection of predicates to check, may not be nullone predicateIllegalArgumentException - if the predicates collection is nullIllegalArgumentException - if any predicate in the collection is nullOnePredicatepublic static <T> Predicate<T> neitherPredicate(Predicate<? super T> predicate1, Predicate<? super T> predicate2)
T - the type that the predicate queriespredicate1 - the first predicate, may not be nullpredicate2 - the second predicate, may not be nullneither predicateIllegalArgumentException - if either predicate is nullNonePredicatepublic static <T> Predicate<T> nonePredicate(Predicate<? super T>... predicates)
T - the type that the predicate queriespredicates - an array of predicates to check, may not be nullnone predicateIllegalArgumentException - if the predicates array is nullIllegalArgumentException - if any predicate in the array is nullNonePredicatepublic static <T> Predicate<T> nonePredicate(Collection<? extends Predicate<T>> predicates)
T - the type that the predicate queriespredicates - a collection of predicates to check, may not be nullnone predicateIllegalArgumentException - if the predicates collection is nullIllegalArgumentException - if any predicate in the collection is nullNonePredicatepublic static <T> Predicate<T> notPredicate(Predicate<? super T> predicate)
T - the type that the predicate queriespredicate - the predicate to notnot predicateIllegalArgumentException - if the predicate is nullNotPredicatepublic static <T> Predicate<T> asPredicate(Transformer<? super T,Boolean> transformer)
T - the type that the predicate queriestransformer - the transformer to wrap, may not be nullIllegalArgumentException - if the transformer is nullTransformerPredicatepublic static <T> Predicate<T> nullIsExceptionPredicate(Predicate<? super T> predicate)
T - the type that the predicate queriespredicate - the predicate to wrap, may not be nullIllegalArgumentException - if the predicate is null.NullIsExceptionPredicatepublic static <T> Predicate<T> nullIsFalsePredicate(Predicate<? super T> predicate)
T - the type that the predicate queriespredicate - the predicate to wrap, may not be nullIllegalArgumentException - if the predicate is null.NullIsFalsePredicatepublic static <T> Predicate<T> nullIsTruePredicate(Predicate<? super T> predicate)
T - the type that the predicate queriespredicate - the predicate to wrap, may not be nullIllegalArgumentException - if the predicate is null.NullIsTruePredicatepublic static <T> Predicate<T> transformedPredicate(Transformer<? super T,? extends T> transformer, Predicate<? super T> predicate)
T - the type that the predicate queriestransformer - the transformer to call firstpredicate - the predicate to call with the result of the transformIllegalArgumentException - if the transformer or the predicate is nullTransformedPredicateCopyright © 2001–2013 The Apache Software Foundation. All rights reserved.