Package net.sf.colossus.util
Class NullCheckPredicate<T>
java.lang.Object
net.sf.colossus.util.NullCheckPredicate<T>
- Type Parameters:
T
- The type of objects to check.
- All Implemented Interfaces:
Predicate<T>
A predicate checking objects on being the null object.
This class can be used on its own, returning the boolean
value given in its constructor for null values and its opposite for
non-null values.
In this case
new NullCheckPredicate(true)
creates a predicate
checking for null values, and new NullCheckPredicate(false)
creates one to check for values other than null.
Alternatively subclasses can overwrite matchesNonNullValue(Object)
,
in which case that determines the value for the non-null objects.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
Returns true iff the given object matches the predicate.protected boolean
matchesNonNullValue
(T object) Can be overwritten to apply further checks for values that are not null.
-
Field Details
-
nullValue
private final boolean nullValue
-
-
Constructor Details
-
NullCheckPredicate
public NullCheckPredicate(boolean nullValue) Creates a new predicate.- Parameters:
nullValue
- The value to return for null.
-
-
Method Details
-
matches
Description copied from interface:Predicate
Returns true iff the given object matches the predicate. Note that null values are allowed and implementers are to return either true or false for them instead of throwing exceptions. -
matchesNonNullValue
Can be overwritten to apply further checks for values that are not null.- Parameters:
object
- The value to check. Not null.- Returns:
- True iff the object matches. In the default implementation the opposite of the null value.
-