Class AbstractEventFilter

  • All Implemented Interfaces:
    EventFilter
    Direct Known Subclasses:
    ClassEventFilter, TypeEventFilter

    public abstract class AbstractEventFilter
    extends Object
    implements EventFilter

    An abstract base class for event filters.

    This class can be used as base class by simple event filters that do not need to bother with specialties like null values or non event objects. The class can be configured whether it should accept null values or not. It can be initialized with a base class that must be derived from BuilderEvent. All objects accepted by this filter must then be of this class or one of its subclasses

    In this class a base implementation of the accept() method is provided, which casts the passed in object to an event object and then delegates to the abstract acceptEvent() method.

    Version:
    $Id: AbstractEventFilter.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • AbstractEventFilter

        protected AbstractEventFilter()
        Creates a new instance of AbstractEventFilter. The base class is set to BuilderEvent; null values won't be accepted.
      • AbstractEventFilter

        protected AbstractEventFilter​(Class<?> baseClass)
        Creates a new instance of AbstractEventFilter and initializes it with the base class. null values won't be accepted.
        Parameters:
        baseClass - the base class (must no be null)
      • AbstractEventFilter

        protected AbstractEventFilter​(Class<?> baseClass,
                                      boolean acceptNull)
        Creates a new instance of AbstractEventFilter and initializes it with the base class and the acceptNull flag.
        Parameters:
        baseClass - the base class (must no be null)
        acceptNull - a flag if null values are accepted
    • Method Detail

      • accept

        public boolean accept​(Object obj)
        Tests whether the passed in object is accepted by this filter. This implementation will perform a type cast an delegate to the acceptEvent(BuilderEvent) method.
        Specified by:
        accept in interface EventFilter
        Parameters:
        obj - the object to test
        Returns:
        a flag if this object is accepted
      • isAcceptNull

        public boolean isAcceptNull()
        Returns the acceptNull flag.
        Returns:
        a flag if null values are accepted
      • setAcceptNull

        public void setAcceptNull​(boolean acceptNull)
        Sets the acceptNull flag. If a null value is passed to the accept() method, the value of this flag is returned.
        Parameters:
        acceptNull - a flag if null values are accepted
      • getBaseClass

        public Class<?> getBaseClass()
        Returns the base class.
        Returns:
        the filter's base class
      • setBaseClass

        public void setBaseClass​(Class<?> baseClass)
        Sets the base class. The passed in class object must not be null and must be derived from BuilderEvent.
        Parameters:
        baseClass - the base class
      • acceptEvent

        protected abstract boolean acceptEvent​(BuilderEvent event)
        Tests if the passed in event object is accepted by this filter. This method is called by the base implementation of accept().
        Parameters:
        event - the event to be tested
        Returns:
        a flag whether the event object is accepted