edu.nrao.sss.util
Class CompoundFilter<T>

java.lang.Object
  extended by edu.nrao.sss.util.CompoundFilter<T>
All Implemented Interfaces:
Filter<T>

public class CompoundFilter<T>
extends Object
implements Filter<T>

A filter that is composed of other filters.

The primary purpose of this class is to allow for the logical (AND / OR) joining of other filters -- including other compound filters. An individual filter uses only AND logic for its criteria. In those situations where you need to allow passage of particles through a filter under condition A OR condition B, create a filter for each condition and add them to a CompoundFilter using the logical OR operator.

Version Info:

$Revision: 819 $
$Date: 2007-08-13 16:25:44 -0600 (Mon, 13 Aug 2007) $
$Author: dharland $ (last person to modify)

Since:
2007-08-13
Author:
David M. Harland

Constructor Summary
CompoundFilter()
          Creates a new wide open filter with the logical AND operator.
CompoundFilter(Collection<? extends Filter<T>> filters, LogicalOperator operator)
          Creates a new compound filter with the given features.
 
Method Summary
 CompoundFilter<T> add(Filter<T> newFilter)
          Adds newFilter as a component of this compound filter.
 CompoundFilter<T> addAll(Collection<? extends Filter<T>> newFilters)
          Adds each of the filters in the collection as components of this compound filter.
 boolean allows(T particle)
          Returns true if this filter allows particle to pass through.
 boolean blocks(T particle)
          Returns true if this filter blocks particle from passing through.
 CompoundFilter<T> remove(Filter<T> unwantedFilter)
          The component filter to be removed from this compound filter.
 CompoundFilter<T> removeAll(Collection<? extends Filter<T>> unwantedFilters)
          The component filters to be removed from this compound filter.
 CompoundFilter<T> removeAllFilters()
          Removes all component filters from this compound filter.
 void setOperator(LogicalOperator newOperator)
          Sets the operator to use when joining the component filters of this compound filter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CompoundFilter

public CompoundFilter()
Creates a new wide open filter with the logical AND operator.


CompoundFilter

public CompoundFilter(Collection<? extends Filter<T>> filters,
                      LogicalOperator operator)
Creates a new compound filter with the given features.

Parameters:
filters - the component filters for this compound filter. If this value is null, it will be treated as an empty collection.
operator - see setOperator(LogicalOperator).
Throws:
IllegalArgumentException - if operator is neither AND nor OR.
Method Detail

add

public CompoundFilter<T> add(Filter<T> newFilter)
Adds newFilter as a component of this compound filter. This filter will hold a reference to newFilter, so changes made to it after this call be reflected herein.

Parameters:
newFilter - a new component filter.
Returns:
this compound filter.

addAll

public CompoundFilter<T> addAll(Collection<? extends Filter<T>> newFilters)
Adds each of the filters in the collection as components of this compound filter.

Parameters:
newFilters - a collection of new component filters.
Returns:
this compound filter.
See Also:
add(Filter)

remove

public CompoundFilter<T> remove(Filter<T> unwantedFilter)
The component filter to be removed from this compound filter.

Parameters:
unwantedFilter - the component filter to be removed.
Returns:
this compound filter.

removeAll

public CompoundFilter<T> removeAll(Collection<? extends Filter<T>> unwantedFilters)
The component filters to be removed from this compound filter.

Parameters:
unwantedFilters - the component filters to be removed.
Returns:
this compound filter.

removeAllFilters

public CompoundFilter<T> removeAllFilters()
Removes all component filters from this compound filter. This action leaves this filter in a wide-open state (i.e., one that allows passage of all particles).


setOperator

public void setOperator(LogicalOperator newOperator)
Sets the operator to use when joining the component filters of this compound filter. The only two legal values are LogicalOperator.AND and LogicalOperator.OR.

The operator is used when deciding whether or not a given particle may pass through this compound filter. In the case of AND, the particle must pass through all the component filters, while in the case of OR it pass through this filter if it passes through any of the component filters.

Parameters:
newOperator - the operator for joining the component filters. This value must be either AND or OR.
Throws:
IllegalArgumentException - if newOperator is neither AND nor OR.

allows

public boolean allows(T particle)
Returns true if this filter allows particle to pass through.

This compound filter delegates filtering decisions to its component filters and uses its logical operator to combine those results. All component filters are subject to the same operator, either AND or OR. Short-circuit logic is used. That is, when using the AND operator, evaluation stops with the first component that blocks the particle; when using the OR operator, evaluation stops with the first component filter that allows passage of the particle.

Specified by:
allows in interface Filter<T>
Parameters:
particle - an object attempting to pass through this filter.
Returns:
true if this filter passes particle.

blocks

public boolean blocks(T particle)
Returns true if this filter blocks particle from passing through. This is a convenience method that is equivalent to !allows(particle).

Specified by:
blocks in interface Filter<T>
Parameters:
particle - an object attempting to pass through this filter.
Returns:
true if this filter blocks particle.


Copyright © 2009. All Rights Reserved.