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<? super 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<? super 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<? super 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<? extends Predicate<? super 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 queriesExceptionPredicate
public static <T> Predicate<T> truePredicate()
T
- the type that the predicate queriesTruePredicate
public static <T> Predicate<T> falsePredicate()
T
- the type that the predicate queriesFalsePredicate
public static <T> Predicate<T> nullPredicate()
T
- the type that the predicate queriesNullPredicate
public static <T> Predicate<T> notNullPredicate()
T
- the type that the predicate queriesNotNullPredicate
public static <T> Predicate<T> equalPredicate(T value)
T
- the type that the predicate queriesvalue
- the value to compare againstEqualPredicate
public static <T> Predicate<T> identityPredicate(T value)
T
- the type that the predicate queriesvalue
- the value to compare againstIdentityPredicate
public static Predicate<Object> instanceofPredicate(Class<?> type)
null
input
object will return false
.type
- the type to check for, may not be nullNullPointerException
- if the class is nullInstanceofPredicate
public 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 queriesUniquePredicate
public 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 nullNullPointerException
- if the methodName is null.InvokerTransformer
,
TransformerPredicate
public 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 argumentsNullPointerException
- if the method name is nullIllegalArgumentException
- if the paramTypes and args don't matchInvokerTransformer
,
TransformerPredicate
public 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
predicateNullPointerException
- if either predicate is nullAndPredicate
public 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
predicateNullPointerException
- if the predicates array is nullNullPointerException
- if any predicate in the array is nullAllPredicate
public static <T> Predicate<T> allPredicate(Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullall
predicateNullPointerException
- if the predicates collection is nullNullPointerException
- if any predicate in the collection is nullAllPredicate
public 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
predicateNullPointerException
- if either predicate is nullOrPredicate
public 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
predicateNullPointerException
- if the predicates array is nullNullPointerException
- if any predicate in the array is nullAnyPredicate
public static <T> Predicate<T> anyPredicate(Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullany
predicateNullPointerException
- if the predicates collection is nullNullPointerException
- if any predicate in the collection is nullAnyPredicate
public 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
predicateNullPointerException
- if either predicate is nullOnePredicate
public 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
predicateNullPointerException
- if the predicates array is nullNullPointerException
- if any predicate in the array is nullOnePredicate
public static <T> Predicate<T> onePredicate(Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullone
predicateNullPointerException
- if the predicates collection is nullNullPointerException
- if any predicate in the collection is nullOnePredicate
public 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
predicateNullPointerException
- if either predicate is nullNonePredicate
public 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
predicateNullPointerException
- if the predicates array is nullNullPointerException
- if any predicate in the array is nullNonePredicate
public static <T> Predicate<T> nonePredicate(Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullnone
predicateNullPointerException
- if the predicates collection is nullNullPointerException
- if any predicate in the collection is nullNonePredicate
public static <T> Predicate<T> notPredicate(Predicate<? super T> predicate)
T
- the type that the predicate queriespredicate
- the predicate to notnot
predicateNullPointerException
- if the predicate is nullNotPredicate
public static <T> Predicate<T> asPredicate(Transformer<? super T,Boolean> transformer)
T
- the type that the predicate queriestransformer
- the transformer to wrap, may not be nullNullPointerException
- if the transformer is nullTransformerPredicate
public static <T> Predicate<T> nullIsExceptionPredicate(Predicate<? super T> predicate)
T
- the type that the predicate queriespredicate
- the predicate to wrap, may not be nullNullPointerException
- if the predicate is null.NullIsExceptionPredicate
public static <T> Predicate<T> nullIsFalsePredicate(Predicate<? super T> predicate)
T
- the type that the predicate queriespredicate
- the predicate to wrap, may not be nullNullPointerException
- if the predicate is null.NullIsFalsePredicate
public static <T> Predicate<T> nullIsTruePredicate(Predicate<? super T> predicate)
T
- the type that the predicate queriespredicate
- the predicate to wrap, may not be nullNullPointerException
- if the predicate is null.NullIsTruePredicate
public 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 transformNullPointerException
- if the transformer or the predicate is nullTransformedPredicate
Copyright © 2001–2019 The Apache Software Foundation. All rights reserved.