Class ChainedEventFilter

  • All Implemented Interfaces:
    EventFilter
    Direct Known Subclasses:
    AndEventFilter, OrEventFilter

    public abstract class ChainedEventFilter
    extends Object
    implements EventFilter

    An abstract base class for filters that operate on multiple filters.

    This class can be used as base class for filters that combine the results of other filters. It supports methods for adding and managing an arbitrary number of (child) filters. The accept() method is not implemented; this is left for concrete subclasses.

    A concrete implementation for instance could invoke its child filters and return only true if all child filters accept the object in question. This would be the implementation of an AND semantics.

    Implementation note: chained filters are not thread-safe. If they are accessed concurrently by different threads synchronization has to be ensured by the developer.

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

      • ChainedEventFilter

        protected ChainedEventFilter()
        Creates a new instance of ChainedEventFilter.
      • ChainedEventFilter

        protected ChainedEventFilter​(Collection<EventFilter> childFilters)
        Creates a new instance of ChainedEventFilter and initializes it with the given list of child filters. The passed in collection must be non null and must not contain any null references.
        Parameters:
        childFilters - a collection with the child filters (must not be null)
        Throws:
        IllegalArgumentException - if the collection with child filters is null or contains a null element
    • Method Detail

      • getFilters

        public List<EventFilter> getFilters()
        Returns a list with all contained filters. This list is never null.
        Returns:
        a (unmodifiable) list with the contained filters
      • getFilterIterator

        protected Iterator<EventFilter> getFilterIterator()
        Returns an iterator to the internal list of child filters. This method is intended to be called by sub classes for iterating over the list of child filters.
        Returns:
        an iterator for iterating over all contained filters
      • addFilter

        public void addFilter​(EventFilter filter)
        Adds the given filter to this chained filter.
        Parameters:
        filter - the filter to be added (must not be null)
        Throws:
        IllegalArgumentException - if the filter is null
      • addFilters

        public void addFilters​(Collection<EventFilter> childFilters)
        Adds all filters in the given collection to this chained filter. The collection must contain non null objects that implement the EventFilter interface.
        Parameters:
        childFilters - the collection with the filters to add (must not be null)
        Throws:
        IllegalArgumentException - if the collection is null or contains a null reference
      • clear

        public void clear()
        Removes all child filters from this chained filter.