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 |
allPredicate(Collection
Create a new Predicate that returns true only if all of the specified predicates are true.
|
static <T> Predicate |
allPredicate(Predicate
Create a new Predicate that returns true only if all of the specified predicates are true.
|
static <T> Predicate |
andPredicate(Predicate
Create a new Predicate that returns true only if both of the specified predicates are true.
|
static <T> Predicate |
anyPredicate(Collection
Create a new Predicate that returns true if any of the specified predicates are true.
|
static <T> Predicate |
anyPredicate(Predicate
Create a new Predicate that returns true if any of the specified predicates are true.
|
static <T> Predicate |
asPredicate(Transformer
Create a new Predicate that wraps a Transformer.
|
static <T> Predicate |
eitherPredicate(Predicate
Create a new Predicate that returns true if one, but not both, of the specified predicates are true.
|
static <T> Predicate |
equalPredicate(T value)
Creates a Predicate that checks if the input object is equal to the specified object using equals().
|
static <T> Predicate |
exceptionPredicate()
Gets a Predicate that always throws an exception.
|
static <T> Predicate |
falsePredicate()
Gets a Predicate that always returns false.
|
static <T> Predicate |
identityPredicate(T value)
Creates a Predicate that checks if the input object is equal to the specified object by identity.
|
static Predicate |
instanceofPredicate(Class
Creates a Predicate that checks if the object passed in is of a particular type, using instanceof.
|
static <T> Predicate |
invokerPredicate(String
Creates a Predicate that invokes a method on the input object.
|
static <T> Predicate |
invokerPredicate(String
Creates a Predicate that invokes a method on the input object.
|
static <T> Predicate |
neitherPredicate(Predicate
Create a new Predicate that returns true if neither of the specified predicates are true.
|
static <T> Predicate |
nonePredicate(Collection
Create a new Predicate that returns true if none of the specified predicates are true.
|
static <T> Predicate |
nonePredicate(Predicate
Create a new Predicate that returns true if none of the specified predicates are true.
|
static <T> Predicate |
notNullPredicate()
Gets a Predicate that checks if the input object passed in is not null.
|
static <T> Predicate |
notPredicate(Predicate
Create a new Predicate that returns true if the specified predicate returns false and vice versa.
|
static <T> Predicate |
nullIsExceptionPredicate(Predicate
Gets a Predicate that throws an exception if the input object is null, otherwise it calls the specified Predicate.
|
static <T> Predicate |
nullIsFalsePredicate(Predicate
Gets a Predicate that returns false if the input object is null, otherwise it calls the specified Predicate.
|
static <T> Predicate |
nullIsTruePredicate(Predicate
Gets a Predicate that returns true if the input object is null, otherwise it calls the specified Predicate.
|
static <T> Predicate |
nullPredicate()
Gets a Predicate that checks if the input object passed in is null.
|
static <T> Predicate |
onePredicate(Collection
Create a new Predicate that returns true if only one of the specified predicates are true.
|
static <T> Predicate |
onePredicate(Predicate
Create a new Predicate that returns true if only one of the specified predicates are true.
|
static <T> Predicate |
orPredicate(Predicate
Create a new Predicate that returns true if either of the specified predicates are true.
|
static <T> Predicate |
transformedPredicate(Transformer
Creates a predicate that transforms the input object before passing it to the predicate.
|
static <T> Predicate |
truePredicate()
Gets a Predicate that always returns true.
|
static <T> Predicate |
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 queries
ExceptionPredicate
public static <T> Predicate<T> truePredicate()
T - the type that the predicate queries
TruePredicate
public static <T> Predicate<T> falsePredicate()
T - the type that the predicate queries
FalsePredicate
public static <T> Predicate<T> nullPredicate()
T - the type that the predicate queries
NullPredicate
public static <T> Predicate<T> notNullPredicate()
T - the type that the predicate queries
NotNullPredicate
public static <T> Predicate<T> equalPredicate(T value)
T - the type that the predicate queries
value - the value to compare against
EqualPredicate
public static <T> Predicate<T> identityPredicate(T value)
T - the type that the predicate queries
value - the value to compare against
IdentityPredicate
public static Predicate<Object > instanceofPredicate(Class <?> type)
null input object will return
false.
type - the type to check for, may not be null
NullPointerException - if the class is null
InstanceofPredicate
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 queries
UniquePredicate
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 queries
methodName - the method name to call on the input object, may not be null
NullPointerException - 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 queries
methodName - the method name to call on the input object, may not be null
paramTypes - the parameter types
args - the arguments
NullPointerException - if the method name is null
IllegalArgumentException - if the paramTypes and args don't match
InvokerTransformer,
TransformerPredicate
public static <T> Predicate<T> andPredicate(Predicate <? super T> predicate1, Predicate <? super T> predicate2)
T - the type that the predicate queries
predicate1 - the first predicate, may not be null
predicate2 - the second predicate, may not be null
and predicate
NullPointerException - if either predicate is null
AndPredicate
public static <T> Predicate<T> allPredicate(Predicate <? super T>... predicates)
T - the type that the predicate queries
predicates - an array of predicates to check, may not be null
all predicate
NullPointerException - if the predicates array is null
NullPointerException - if any predicate in the array is null
AllPredicate
public static <T> Predicate<T> allPredicate(Collection <? extends Predicate <? super T>> predicates)
T - the type that the predicate queries
predicates - a collection of predicates to check, may not be null
all predicate
NullPointerException - if the predicates collection is null
NullPointerException - if any predicate in the collection is null
AllPredicate
public static <T> Predicate<T> orPredicate(Predicate <? super T> predicate1, Predicate <? super T> predicate2)
T - the type that the predicate queries
predicate1 - the first predicate, may not be null
predicate2 - the second predicate, may not be null
or predicate
NullPointerException - if either predicate is null
OrPredicate
public static <T> Predicate<T> anyPredicate(Predicate <? super T>... predicates)
T - the type that the predicate queries
predicates - an array of predicates to check, may not be null
any predicate
NullPointerException - if the predicates array is null
NullPointerException - if any predicate in the array is null
AnyPredicate
public static <T> Predicate<T> anyPredicate(Collection <? extends Predicate <? super T>> predicates)
T - the type that the predicate queries
predicates - a collection of predicates to check, may not be null
any predicate
NullPointerException - if the predicates collection is null
NullPointerException - if any predicate in the collection is null
AnyPredicate
public static <T> Predicate<T> eitherPredicate(Predicate <? super T> predicate1, Predicate <? super T> predicate2)
T - the type that the predicate queries
predicate1 - the first predicate, may not be null
predicate2 - the second predicate, may not be null
either predicate
NullPointerException - if either predicate is null
OnePredicate
public static <T> Predicate<T> onePredicate(Predicate <? super T>... predicates)
T - the type that the predicate queries
predicates - an array of predicates to check, may not be null
one predicate
NullPointerException - if the predicates array is null
NullPointerException - if any predicate in the array is null
OnePredicate
public static <T> Predicate<T> onePredicate(Collection <? extends Predicate <? super T>> predicates)
T - the type that the predicate queries
predicates - a collection of predicates to check, may not be null
one predicate
NullPointerException - if the predicates collection is null
NullPointerException - if any predicate in the collection is null
OnePredicate
public static <T> Predicate<T> neitherPredicate(Predicate <? super T> predicate1, Predicate <? super T> predicate2)
T - the type that the predicate queries
predicate1 - the first predicate, may not be null
predicate2 - the second predicate, may not be null
neither predicate
NullPointerException - if either predicate is null
NonePredicate
public static <T> Predicate<T> nonePredicate(Predicate <? super T>... predicates)
T - the type that the predicate queries
predicates - an array of predicates to check, may not be null
none predicate
NullPointerException - if the predicates array is null
NullPointerException - if any predicate in the array is null
NonePredicate
public static <T> Predicate<T> nonePredicate(Collection <? extends Predicate <? super T>> predicates)
T - the type that the predicate queries
predicates - a collection of predicates to check, may not be null
none predicate
NullPointerException - if the predicates collection is null
NullPointerException - if any predicate in the collection is null
NonePredicate
public static <T> Predicate<T> notPredicate(Predicate <? super T> predicate)
T - the type that the predicate queries
predicate - the predicate to not
not predicate
NullPointerException - if the predicate is null
NotPredicate
public static <T> Predicate<T> asPredicate(Transformer <? super T ,Boolean > transformer)
T - the type that the predicate queries
transformer - the transformer to wrap, may not be null
NullPointerException - if the transformer is null
TransformerPredicate
public static <T> Predicate<T> nullIsExceptionPredicate(Predicate <? super T> predicate)
T - the type that the predicate queries
predicate - the predicate to wrap, may not be null
NullPointerException - if the predicate is null.
NullIsExceptionPredicate
public static <T> Predicate<T> nullIsFalsePredicate(Predicate <? super T> predicate)
T - the type that the predicate queries
predicate - the predicate to wrap, may not be null
NullPointerException - if the predicate is null.
NullIsFalsePredicate
public static <T> Predicate<T> nullIsTruePredicate(Predicate <? super T> predicate)
T - the type that the predicate queries
predicate - the predicate to wrap, may not be null
NullPointerException - 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 queries
transformer - the transformer to call first
predicate - the predicate to call with the result of the transform
NullPointerException - if the transformer or the predicate is null
TransformedPredicate