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>

public class NullCheckPredicate<T> extends Object implements 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
    Modifier and Type
    Field
    Description
    private final boolean
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    NullCheckPredicate(boolean nullValue)
    Creates a new predicate.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    matches(T object)
    Returns true iff the given object matches the predicate.
    protected boolean
    Can be overwritten to apply further checks for values that are not null.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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

      public final boolean matches(T object)
      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.
      Specified by:
      matches in interface Predicate<T>
      Parameters:
      object - The object to test. May be null.
      Returns:
      true iff the object matches.
    • matchesNonNullValue

      protected boolean matchesNonNullValue(T object)
      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.