public class PredicateUtils
extends java.lang.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(java.util.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(java.util.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,java.lang.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<java.lang.Object> |
instanceofPredicate(java.lang.Class<?> type)
Creates a Predicate that checks if the object passed in is of
a particular type, using instanceof.
|
static <T> Predicate<T> |
invokerPredicate(java.lang.String methodName)
Creates a Predicate that invokes a method on the input object.
|
static <T> Predicate<T> |
invokerPredicate(java.lang.String methodName,
java.lang.Class<?>[] paramTypes,
java.lang.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(java.util.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(java.util.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<java.lang.Object> instanceofPredicate(java.lang.Class<?> type)
null
input
object will return false
.type
- the type to check for, may not be nulljava.lang.NullPointerException
- 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(java.lang.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 nulljava.lang.NullPointerException
- if the methodName is null.InvokerTransformer
,
TransformerPredicate
public static <T> Predicate<T> invokerPredicate(java.lang.String methodName, java.lang.Class<?>[] paramTypes, java.lang.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 argumentsjava.lang.NullPointerException
- if the method name is nulljava.lang.IllegalArgumentException
- 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
predicatejava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- if the predicates array is nulljava.lang.NullPointerException
- if any predicate in the array is nullAllPredicate
public static <T> Predicate<T> allPredicate(java.util.Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullall
predicatejava.lang.NullPointerException
- if the predicates collection is nulljava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- if the predicates array is nulljava.lang.NullPointerException
- if any predicate in the array is nullAnyPredicate
public static <T> Predicate<T> anyPredicate(java.util.Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullany
predicatejava.lang.NullPointerException
- if the predicates collection is nulljava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- if the predicates array is nulljava.lang.NullPointerException
- if any predicate in the array is nullOnePredicate
public static <T> Predicate<T> onePredicate(java.util.Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullone
predicatejava.lang.NullPointerException
- if the predicates collection is nulljava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- if the predicates array is nulljava.lang.NullPointerException
- if any predicate in the array is nullNonePredicate
public static <T> Predicate<T> nonePredicate(java.util.Collection<? extends Predicate<? super T>> predicates)
T
- the type that the predicate queriespredicates
- a collection of predicates to check, may not be nullnone
predicatejava.lang.NullPointerException
- if the predicates collection is nulljava.lang.NullPointerException
- 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
predicatejava.lang.NullPointerException
- if the predicate is nullNotPredicate
public static <T> Predicate<T> asPredicate(Transformer<? super T,java.lang.Boolean> transformer)
T
- the type that the predicate queriestransformer
- the transformer to wrap, may not be nulljava.lang.NullPointerException
- 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 nulljava.lang.NullPointerException
- 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 nulljava.lang.NullPointerException
- 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 nulljava.lang.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 queriestransformer
- the transformer to call firstpredicate
- the predicate to call with the result of the transformjava.lang.NullPointerException
- if the transformer or the predicate is nullTransformedPredicate
"Copyright © 2010 - 2020 Adobe Systems Incorporated. All Rights Reserved"