|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.collections15.functors.predicate.PredicateUtils
public class PredicateUtils
PredicateUtils
provides reference implementations and utilities
for the Predicate
functor interface. The supplied
Predicate
s are:
boolean
or Boolean
).true
only if the input object is an instance of a specified
class.true
only if the input object is
equal to a specified object (according to the Object.equals(Object)
contract).
true
only if the input object
is the same as a specified object (i.e. the input and specified references
refer to the same object instance).true
only if the input object is null
.true
only if the input object is not null
.true
only if the input object has not
already been evaluated by the Predicate
.true
only if all of the decorated
Predicate
s return true
.true
if any of the decorated Predicate
s return
true
.true
if only
one of the decorated Predicate
s returns true
.true
only if none of the decorated
Predicate
s return true
.Predicate
.Transformer
whose output type is Boolean
.true
.false
.Predicate
with specific handling for a null
input
object.Predicate
.Serializable
.
Constructor Summary | |
---|---|
protected |
PredicateUtils()
Protected constructor prevents direct instantiation, but allows users to extend this library to provide their own augmented static library class. |
Method Summary | ||
---|---|---|
static
|
allPredicate(java.util.Collection<Predicate<? super T>> predicates)
Returns a Predicate that wraps the specified collection of
Predicate s, and which returns true only if all
of the specified Predicate s return true . |
|
static
|
anyPredicate(java.util.Collection<Predicate<? super T>> predicates)
Returns a Predicate that wraps the specified collection of
Predicate s, and which returns true if any one
of the specified Predicate s return true . |
|
static
|
asPredicate(Transformer<T,java.lang.Boolean> transformer)
Returns a Predicate that evaluates input objects using the
specified Transformer . |
|
static
|
equalPredicate(T value)
Returns a Predicate instance whose evaluate
method returns true only if the input object is equal to the
specified value, according to the Object.equals(Object)
contract. |
|
static
|
exceptionPredicate()
Returns a Predicate instance whose evaluate
method always throws an exception. |
|
static
|
falsePredicate()
Returns a Predicate instance whose evaluate
method always returns false . |
|
static
|
instanceofPredicate(java.lang.Class<? extends T> type)
Returns a Predicate instance whose evaluate
method returns true only if the input object is an instance
of the specified type. |
|
static
|
invokerPredicate(java.lang.String methodName)
Returns a Predicate that invokes a method on the input
object, which must return either a boolean or
Boolean , and have no parameters. |
|
static
|
invokerPredicate(java.lang.String methodName,
java.lang.Class[] paramTypes,
java.lang.Object[] args)
Returns a Predicate that invokes a method on the input
object, which must return either a boolean or
Boolean , and have the specified parameters. |
|
static
|
nonePredicate(java.util.Collection<Predicate<? super T>> predicates)
Returns a Predicate that wraps the specified collection of
Predicate s, and which returns true unless any
one of the specified Predicate s return true . |
|
static
|
notNullPredicate()
Returns a Predicate instance whose evaluate
method returns true only if the input object is not
null . |
|
static
|
notPredicate(Predicate<T> predicate)
Returns a Predicate whose evaluate method
returns the inverse of the decorated Predicate 's
evaluate method. |
|
static
|
nullIsExceptionPredicate(Predicate<T> predicate)
Returns a Predicate that decorates the specified
Predicate , throwing an exception for any null
input object. |
|
static
|
nullIsFalsePredicate(Predicate<T> predicate)
Returns a Predicate that decorates the specified
Predicate , returning false for any
null input object. |
|
static
|
nullIsTruePredicate(Predicate<T> predicate)
Returns a Predicate that decorates the specified
Predicate , returning true for any
null input object. |
|
static
|
nullPredicate()
Returns a Predicate instance whose evaluate
method returns true only if the input object is
null . |
|
static
|
onePredicate(java.util.Collection<Predicate<? super T>> predicates)
Returns a Predicate that wraps the specified collection of
Predicate s, and which returns true if only one
of the specified Predicate s return true . |
|
static
|
samePredicate(T value)
Returns a Predicate instance whose evaluate
method returns true only if the input object is the same as
the specified value (i.e. |
|
static
|
transformedPredicate(Transformer<? super E,? extends D> transformer,
Predicate<? super D> predicate)
Returns a Predicate whose evaluate method
transforms an input object and evaluates the result using another
Predicate instance. |
|
static
|
truePredicate()
Returns a Predicate instance whose evaluate
method always returns true . |
|
static
|
uniquePredicate()
Returns a Predicate which returns true the
first time any given object is evaluated, and returns false
each time the same object is subsequently evaluated. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected PredicateUtils()
Method Detail |
---|
public static <T> Predicate<T> exceptionPredicate()
Predicate
instance whose evaluate
method always throws an exception.
Predicate
instance whose evaluate
method always throws an exception.ExceptionPredicate
public static <T> Predicate<T> truePredicate()
Predicate
instance whose evaluate
method always returns true
.
Predicate
instance whose evaluate
method always returns true
.TruePredicate
public static <T> Predicate<T> falsePredicate()
Predicate
instance whose evaluate
method always returns false
.
Predicate
instance whose evaluate
method always returns false
.FalsePredicate
public static <T> Predicate<T> nullPredicate()
Predicate
instance whose evaluate
method returns true
only if the input object is
null
.
Predicate
instance whose evaluate
method returns true
only if the input object is
null
.NullPredicate
public static <T> Predicate<T> notNullPredicate()
Predicate
instance whose evaluate
method returns true
only if the input object is not
null
.
Predicate
instance whose evaluate
method returns true
only if the input object is not
null
.NotNullPredicate
public static <T> Predicate<T> equalPredicate(T value)
Predicate
instance whose evaluate
method returns true
only if the input object is equal to the
specified value, according to the Object.equals(Object)
contract.
value
- The object to which input objects are compared.
Predicate
instance whose evaluate
method returns true
only if the input object is
equal to the specified value, according to the
Object.equals(Object)
contract.
java.lang.IllegalArgumentException
- Thrown if the specified value object is
null
.EqualPredicate
,
samePredicate(T)
public static <T> Predicate<T> samePredicate(T value)
Predicate
instance whose evaluate
method returns true
only if the input object is the same as
the specified value (i.e. only if the input object reference and the
value object reference both refer to the same object instance).
value
- The object to which input objects are compared.
Predicate
instance whose evaluate
method returns true
only if the input object is the
same as the specified value (i.e. only if the input object
reference and the value object reference both refer to the same
object instance).
java.lang.IllegalArgumentException
- Thrown if the specified value object is
null
.SamePredicate
,
equalPredicate(T)
public static <T> Predicate<T> instanceofPredicate(java.lang.Class<? extends T> type)
Predicate
instance whose evaluate
method returns true
only if the input object is an instance
of the specified type.
type
- The type to compare input objects to.
Predicate
instance whose evaluate
method returns true
only if the input object is an
instance of the specified type.
java.lang.IllegalArgumentException
- Thrown if the specified type is
null
.InstanceofPredicate
public static <T> Predicate<T> uniquePredicate()
Predicate
which returns true
the
first time any given object is evaluated, and returns false
each time the same object is subsequently evaluated.
Predicate
which returns true
the
first time any given object is evaluated, and returns
false
each time the same object is subsequently
evaluated.UniquePredicate
public static <T> Predicate<T> invokerPredicate(java.lang.String methodName)
Predicate
that invokes a method on the input
object, which must return either a boolean
or
Boolean
, and have no parameters.
For example, PredicateUtils.invokerPredicate("isEmpty");
will call the isEmpty
method on the input object to
determine the predicate result.
If the input object is null
, or does not have the named
method with the appropriate signature, an exception is thrown.
methodName
- The method name to call on the input object.
Predicate
that invokes a method on the input
object, which must return either a boolean
or
Boolean
, and have no parameters.
java.lang.IllegalArgumentException
- If the method name is null
.InvokerTransformer
,
TransformerPredicate
public static <T> Predicate<T> invokerPredicate(java.lang.String methodName, java.lang.Class[] paramTypes, java.lang.Object[] args)
Predicate
that invokes a method on the input
object, which must return either a boolean
or
Boolean
, and have the specified parameters.
If the input object is null
, or does not have the named
method with the appropriate signature, an exception is thrown.
methodName
- The method name to call on the input object.paramTypes
- The types of the arguments of the method to invoke on
the input object.args
- The arguments to pass to the method invoked on the
input object.
Predicate
that invokes a method on the input
object, which must return either a boolean
or
Boolean
, and have the specified parameters.
java.lang.IllegalArgumentException
- If the method name is null
.
java.lang.IllegalArgumentException
- If paramTypes
is
null
, or contains any
null
classes.
java.lang.IllegalArgumentException
- If args
is null
,
contains a different number of elements
to paramTypes
, or if any of
its elements doen't match the
corresponding type in paramTypes
.InvokerTransformer
,
TransformerPredicate
public static <T> Predicate<T> allPredicate(java.util.Collection<Predicate<? super T>> predicates)
Predicate
that wraps the specified collection of
Predicate
s, and which returns true
only if all
of the specified Predicate
s return true
.
predicates
- The Predicate
instance that will evaluate to
true
unless any of the wrapped Predicate
s
evaluate to false
.
java.lang.IllegalArgumentException
- Thrown if the collection, or any of its
elements are null
. The
collection may be empty, however, in
which case the resulting Predicate
will always return true
.AllPredicate
public static <T> Predicate<T> anyPredicate(java.util.Collection<Predicate<? super T>> predicates)
Predicate
that wraps the specified collection of
Predicate
s, and which returns true
if any one
of the specified Predicate
s return true
.
predicates
- The Predicate
instance that will evaluate to
true
if any of the wrapped Predicate
s
evaluate to true
.
java.lang.IllegalArgumentException
- Thrown if the collection, or any of its
elements are null
. The
collection may be empty, however, in
which case the resulting AnyPredicate
will always return false
.AnyPredicate
public static <T> Predicate<T> onePredicate(java.util.Collection<Predicate<? super T>> predicates)
Predicate
that wraps the specified collection of
Predicate
s, and which returns true
if only one
of the specified Predicate
s return true
.
predicates
- The Predicate
instance that will only evaluate to
true
if exactly one of the wrapped
Predicate
s evaluates to true
.
java.lang.IllegalArgumentException
- Thrown if the collection, or any of its
elements are null
. The
collection may be empty, however, in
which case the resulting AnyPredicate
will always return false
.OnePredicate
public static <T> Predicate<T> nonePredicate(java.util.Collection<Predicate<? super T>> predicates)
Predicate
that wraps the specified collection of
Predicate
s, and which returns true
unless any
one of the specified Predicate
s return true
.
predicates
- The Predicate
instance that will evaluate to
true
unless any of the wrapped Predicate
s
evaluate to true
.
java.lang.IllegalArgumentException
- Thrown if the collection, or any of its
elements are null
. The
collection may be empty, however, in
which case the resulting AnyPredicate
will always return true
.NonePredicate
public static <T> Predicate<T> notPredicate(Predicate<T> predicate)
Predicate
whose evaluate
method
returns the inverse of the decorated Predicate
's
evaluate
method.
predicate
- The decorated Predicate
.
java.lang.IllegalArgumentException
- Thrown if the decorated Predicate
is null
.public static <T> Predicate<T> asPredicate(Transformer<T,java.lang.Boolean> transformer)
Predicate
that evaluates input objects using the
specified Transformer
. The Predicate
evaluates
true
if the Transformer
returns
Boolean.TRUE
, and evaluates to false
if the
Transformer
returns Boolean.False
or
null
.
transformer
- The Transformer
to use.
Predicate
that evaluates input objects using the
specified Transformer
.
java.lang.IllegalArgumentException
- Thrown if the transformer
argument is null
.public static <T> Predicate<T> nullIsExceptionPredicate(Predicate<T> predicate)
Predicate
that decorates the specified
Predicate
, throwing an exception for any null
input object.
predicate
- The decorated Predicate
that is delgated to
if the null
check doesn't throw an
exception.
Predicate
that decorates the specified
Predicate
, throwing an exception for any
null
input object.
java.lang.IllegalArgumentException
- Thrown if the specified Predicate
to decorate is null
.NullIsExceptionPredicate
public static <T> Predicate<T> nullIsFalsePredicate(Predicate<T> predicate)
Predicate
that decorates the specified
Predicate
, returning false
for any
null
input object.
predicate
- The decorated Predicate
that is delgated to
if the null
check doesn't cause
false
to be returned.
Predicate
that decorates the specified
Predicate
, returning false
for any
null
input object.
java.lang.IllegalArgumentException
- Thrown if the specified Predicate
to decorate is null
.NullIsFalsePredicate
public static <T> Predicate<T> nullIsTruePredicate(Predicate<T> predicate)
Predicate
that decorates the specified
Predicate
, returning true
for any
null
input object.
predicate
- The decorated Predicate
that is delgated to
if the null
check doesn't cause
true
to be returned.
Predicate
that decorates the specified
Predicate
, returning true
for any
null
input object.
java.lang.IllegalArgumentException
- Thrown if the specified Predicate
to decorate is null
.NullIsTruePredicate
public static <E,D> Predicate<E> transformedPredicate(Transformer<? super E,? extends D> transformer, Predicate<? super D> predicate)
Predicate
whose evaluate
method
transforms an input object and evaluates the result using another
Predicate
instance.
transformer
- The Transformer
used to transform an
input object prior to evaluation.predicate
- The Predicate
used to evaluate the
transformed input object.
Predicate
whose evaluate
method
transforms an input object and evaluates the result using another
Predicate
instance.
java.lang.IllegalArgumentException
- If either argument is null
.TransformedPredicate
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |