Dashboard Builder Commons 6.0.0.Beta4

org.jboss.dashboard.commons.filter
Class AbstractFilter

java.lang.Object
  extended by org.jboss.dashboard.commons.filter.AbstractFilter
All Implemented Interfaces:
Cloneable, Filter, FilterByCriteria
Direct Known Subclasses:
ThreadProfileFilter

public abstract class AbstractFilter
extends Object
implements FilterByCriteria, Cloneable

An abstract that defines those basic services a entity filter.


Field Summary
protected  ThreadLocal _bshIntepreterThread
          BSH interpreter per thread cache.
protected  Map _filterVarValues
          Map used to store properties filter results when evauating the overall filter condition.
protected  String filterCondition
          The filter condition logical expression.
protected  List filterProperties
          Filter list.
protected  String gt
          Greater than symbol.
protected  String gtOrEq
          Greater or equals than symbol.
protected  Locale locale
          The criteria locale.
protected  String lt
          Less than symbol.
protected  String ltOrEq
          Less or equals than symbol.
protected  String wildcard
          Wildcard symbol.
 
Fields inherited from interface org.jboss.dashboard.commons.filter.FilterByCriteria
ALLOW_ALL, ALLOW_ANY, ALLOW_NONE
 
Constructor Summary
AbstractFilter()
           
 
Method Summary
 void addProperties(FilterByCriteria filter)
          Add all the specified filter properties.
 void addProperty(String propertyId, Object minValue, boolean minValueIncluded, Object maxValue, boolean maxValueIncluded, Collection allowedValues, int allowMode)
          Specifies a property for the filter.
 boolean addProperty(String propertyId, String filterCriteria)
          Specifies a property for the filter in a unstructured way.
 FilterByCriteria cloneFilter()
          Create an exact copy of this filter instance.
 int compare(Comparable o1, Comparable o2, int ordering)
          Compares two comparable objects.
protected  int compareBySimilarity(String propertyId, Object pattern, Object value)
          Check if the given object instance matchs the specified pattern.
 boolean containsProperty(Collection propIds)
          Check if a filter is defined for any of the property identifiers given.
 boolean containsProperty(String propertyId)
          Check if the given property filter has been defined.
 boolean equals(Object obj)
           
protected  Object executeBeanShellScript(String beanShellScript, Map context)
          Executes a BeanShell script.
protected abstract  String formatForComparison(String propertyId, Object value)
          Format a given property value valid for string comparfison against other values.
protected abstract  String formatForDisplay(String propertyId, Object value)
          Format a given property value as displayed for the the user.
 String getExtraInfo(String propertyId)
           
 String getFilterCondition()
           
 String getGt()
          The greater than symbol.
 String getGtOrEq()
          The greater or equals than symbol.
 Locale getLocale()
          The criteria always belongs to a locale.
 String getLt()
          The less than symbol.
 String getLtOrEq()
          The less or equals than symbol.
protected  Object[] getProperty(String propertyId)
           
 List getPropertyAllowedValues(String propertyId)
          Get the set of allowed values for the property.
 int getPropertyAllowMode(String propertyId)
          Get the allow mode for a property.
 String[] getPropertyIds()
          Retgrieve the property ids. specified for this filter.
 Comparable getPropertyMaxValue(String propertyId)
          Get the max. value allowed for the property in the filter.
 Comparable getPropertyMinValue(String propertyId)
          Get the min. value allowed for the property in the filter.
 int getPropertyPriority(String propertyId)
          Get the prioority for a given property defined in the filter.
protected abstract  Object getPropertyValue(String propertyId, Object obj)
          Retrieve the value for a given property.
 String getVariableName(String propertyId)
           
 String getWildcard()
          The wildcard symbol used by the filter to compare properties.
 boolean maxValueIncluded(String propertyId)
          Check if max. value defined must be considered as valid.
 boolean minValueIncluded(String propertyId)
          Check if min. value defined must be considered as valid.
 boolean pass(Map obj)
          Apply the filter to the given object.
 boolean pass(Object obj)
          Apply the filter to the given object.
 boolean pass(String propertyId, Object value)
          Check if a value satisfies a property filter.
 boolean pass(String propertyId, Object value, List allowedValues, int allowMode)
          Check if a given value (either a single object or a collection) satisfies a collection of allowed values.
 boolean passValue(String propertyId, Object value, List allowedValues, int allowMode)
          Check if a given value satisfies a collection of allowed values.
 void removeAllProperty()
          Clear filter.
 void removeProperties(FilterByCriteria filter)
          Remove all the specified filter properties.
 void removeProperty(String propertyId)
          Remove property from the filter.
 void setExtraInfo(String propertyId, String extraInfo)
          Set additional information regarding the property.
 void setFilterCondition(String logicalExpression)
          Define the condition to be applied to the set of property filters when executing the pass(Object) method.
 void setGt(String gt)
           
 void setGtOrEq(String gtOrEq)
           
 void setLocale(Locale locale)
           
 void setLt(String lt)
           
 void setLtOrEq(String ltOrEq)
           
 void setVariableName(String propertyId, String varName)
          An alias or variable to be assigned to the property .
 void setWildcard(String wildcard)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

filterProperties

protected List filterProperties
Filter list. Each entry contains a filter properties array of Object[9] (property id, filter max/min interval, max/min values included, set of allowed values and allow mode, property alias, extra info). The position in the list determines the filter priority in descending order: the first filter into the list is the most prioritary.


filterCondition

protected String filterCondition
The filter condition logical expression.


wildcard

protected String wildcard
Wildcard symbol.


gt

protected String gt
Greater than symbol.


lt

protected String lt
Less than symbol.


gtOrEq

protected String gtOrEq
Greater or equals than symbol.


ltOrEq

protected String ltOrEq
Less or equals than symbol.


locale

protected Locale locale
The criteria locale.


_filterVarValues

protected transient Map _filterVarValues
Map used to store properties filter results when evauating the overall filter condition.


_bshIntepreterThread

protected transient ThreadLocal _bshIntepreterThread
BSH interpreter per thread cache.

Constructor Detail

AbstractFilter

public AbstractFilter()
Method Detail

getLocale

public Locale getLocale()
Description copied from interface: FilterByCriteria
The criteria always belongs to a locale.

Specified by:
getLocale in interface FilterByCriteria

setLocale

public void setLocale(Locale locale)
Specified by:
setLocale in interface FilterByCriteria

getWildcard

public String getWildcard()
Description copied from interface: FilterByCriteria
The wildcard symbol used by the filter to compare properties.

Specified by:
getWildcard in interface FilterByCriteria

setWildcard

public void setWildcard(String wildcard)

getGt

public String getGt()
Description copied from interface: FilterByCriteria
The greater than symbol.

Specified by:
getGt in interface FilterByCriteria

setGt

public void setGt(String gt)

getGtOrEq

public String getGtOrEq()
Description copied from interface: FilterByCriteria
The greater or equals than symbol.

Specified by:
getGtOrEq in interface FilterByCriteria

setGtOrEq

public void setGtOrEq(String gtOrEq)

getLt

public String getLt()
Description copied from interface: FilterByCriteria
The less than symbol.

Specified by:
getLt in interface FilterByCriteria

setLt

public void setLt(String lt)

getLtOrEq

public String getLtOrEq()
Description copied from interface: FilterByCriteria
The less or equals than symbol.

Specified by:
getLtOrEq in interface FilterByCriteria

setLtOrEq

public void setLtOrEq(String ltOrEq)

addProperties

public void addProperties(FilterByCriteria filter)
Description copied from interface: FilterByCriteria
Add all the specified filter properties.

Specified by:
addProperties in interface FilterByCriteria

addProperty

public void addProperty(String propertyId,
                        Object minValue,
                        boolean minValueIncluded,
                        Object maxValue,
                        boolean maxValueIncluded,
                        Collection allowedValues,
                        int allowMode)
Description copied from interface: FilterByCriteria
Specifies a property for the filter.

Specified by:
addProperty in interface FilterByCriteria
Parameters:
propertyId - The property to set.
minValue - The minimun value allowed for the property.
minValueIncluded - The minimun value is considered as a valid value.
maxValue - The maximum value allowed for the property.
maxValueIncluded - The maximum value is considered as a valid value.
allowedValues - A set of values allowed.
allowMode -
  • ALLOW_ALL=All values must be satisfied.
  • ALLOW_ANY=At least one value must be satisfied.
  • ALLOW_NONE=Any value must be satisfied.

addProperty

public boolean addProperty(String propertyId,
                           String filterCriteria)
Description copied from interface: FilterByCriteria
Specifies a property for the filter in a unstructured way.

Specified by:
addProperty in interface FilterByCriteria
Parameters:
propertyId - The property to set.
filterCriteria - The criteria for the property. Operators are allowed here: wildcard, greater than, less than and comma. e.g: ">1000", "Rev*", "1000, 1002, 1003".
Returns:
Property added or not. e.g: If criteria string is empty then it returns false.

removeProperty

public void removeProperty(String propertyId)
Description copied from interface: FilterByCriteria
Remove property from the filter.

Specified by:
removeProperty in interface FilterByCriteria

removeProperties

public void removeProperties(FilterByCriteria filter)
Description copied from interface: FilterByCriteria
Remove all the specified filter properties.

Specified by:
removeProperties in interface FilterByCriteria

removeAllProperty

public void removeAllProperty()
Description copied from interface: FilterByCriteria
Clear filter.

Specified by:
removeAllProperty in interface FilterByCriteria

getPropertyPriority

public int getPropertyPriority(String propertyId)
Description copied from interface: FilterByCriteria
Get the prioority for a given property defined in the filter.

Specified by:
getPropertyPriority in interface FilterByCriteria
Returns:
A priority ordinal.

getPropertyMinValue

public Comparable getPropertyMinValue(String propertyId)
Description copied from interface: FilterByCriteria
Get the min. value allowed for the property in the filter.

Specified by:
getPropertyMinValue in interface FilterByCriteria

minValueIncluded

public boolean minValueIncluded(String propertyId)
Description copied from interface: FilterByCriteria
Check if min. value defined must be considered as valid. To be applied only when min. value is defined.

Specified by:
minValueIncluded in interface FilterByCriteria

getPropertyMaxValue

public Comparable getPropertyMaxValue(String propertyId)
Description copied from interface: FilterByCriteria
Get the max. value allowed for the property in the filter.

Specified by:
getPropertyMaxValue in interface FilterByCriteria

maxValueIncluded

public boolean maxValueIncluded(String propertyId)
Description copied from interface: FilterByCriteria
Check if max. value defined must be considered as valid. To be applied only when max. value is defined.

Specified by:
maxValueIncluded in interface FilterByCriteria

getPropertyAllowedValues

public List getPropertyAllowedValues(String propertyId)
Description copied from interface: FilterByCriteria
Get the set of allowed values for the property.

Specified by:
getPropertyAllowedValues in interface FilterByCriteria

getPropertyAllowMode

public int getPropertyAllowMode(String propertyId)
Description copied from interface: FilterByCriteria
Get the allow mode for a property.

Specified by:
getPropertyAllowMode in interface FilterByCriteria
Returns:
See ALLOW_ constants defined.

setVariableName

public void setVariableName(String propertyId,
                            String varName)
Description copied from interface: FilterByCriteria
An alias or variable to be assigned to the property . Useful in the definition of custom filter conditions. Such variable it models the boolean result obtained after applying the property filter for a given object. This variable can be used in the definition of custom filter conditions for the filter (as a boolean expressions).

For more details see setFilterCondition(String logicalExpression) method.

Specified by:
setVariableName in interface FilterByCriteria

getVariableName

public String getVariableName(String propertyId)
Specified by:
getVariableName in interface FilterByCriteria

getExtraInfo

public String getExtraInfo(String propertyId)
Specified by:
getExtraInfo in interface FilterByCriteria

setExtraInfo

public void setExtraInfo(String propertyId,
                         String extraInfo)
Description copied from interface: FilterByCriteria
Set additional information regarding the property. f.i: the text an user typed as a search criteria for a given property.

Specified by:
setExtraInfo in interface FilterByCriteria

setFilterCondition

public void setFilterCondition(String logicalExpression)
Description copied from interface: FilterByCriteria
Define the condition to be applied to the set of property filters when executing the pass(Object) method.

Specified by:
setFilterCondition in interface FilterByCriteria
Parameters:
logicalExpression - A logical expression where we can combine the different property pass results in order to calculate the overall filter result. Boolean AND, OR and NOT operators are supported.

Next some logical expressions samples:

First of all, define variables for properties.
  • setVariableName("processId", "a");
  • setVariableName("stepName", "b");
  • setVariableName("processDescrCode", "c");
    Second step, define filter logical expression:
  • Sample 1: setFilterCondition("NOT a OR b");
  • Sample 2: setFilterCondition("c AND (a OR b)");

As you can see, powerful and complex boolean expressions can be defined.


getFilterCondition

public String getFilterCondition()

getPropertyIds

public String[] getPropertyIds()
Description copied from interface: FilterByCriteria
Retgrieve the property ids. specified for this filter.

Specified by:
getPropertyIds in interface FilterByCriteria
Returns:
An array of ids.

containsProperty

public boolean containsProperty(String propertyId)
Description copied from interface: FilterByCriteria
Check if the given property filter has been defined.

Specified by:
containsProperty in interface FilterByCriteria

containsProperty

public boolean containsProperty(Collection propIds)
Description copied from interface: FilterByCriteria
Check if a filter is defined for any of the property identifiers given.

Specified by:
containsProperty in interface FilterByCriteria
Parameters:
propIds - A collection of property identifiers.

getProperty

protected Object[] getProperty(String propertyId)

toString

public String toString()
Overrides:
toString in class Object

pass

public boolean pass(String propertyId,
                    Object value)
             throws IllegalArgumentException
Check if a value satisfies a property filter.

Specified by:
pass in interface FilterByCriteria
Parameters:
propertyId - The property to pass.
value - The value to check.
Throws:
IllegalArgumentException

pass

public boolean pass(String propertyId,
                    Object value,
                    List allowedValues,
                    int allowMode)
Check if a given value (either a single object or a collection) satisfies a collection of allowed values.

Parameters:
value -
allowedValues -
allowMode - See ALLOW_ constants defined.

passValue

public boolean passValue(String propertyId,
                         Object value,
                         List allowedValues,
                         int allowMode)
Check if a given value satisfies a collection of allowed values.

Parameters:
value -
allowedValues -
allowMode - See ALLOW_ constants defined.

compareBySimilarity

protected int compareBySimilarity(String propertyId,
                                  Object pattern,
                                  Object value)
Check if the given object instance matchs the specified pattern.

Parameters:
propertyId - The property to compare.
pattern - The pattern. In Strings wildcard is accepted.
value - The object to check.
Returns:
Equality comparison if pattern has no wildcards.

pass

public boolean pass(Map obj)
Description copied from interface: Filter
Apply the filter to the given object.

Specified by:
pass in interface Filter
Parameters:
obj - A map containing pairs of [propertyId (String), propertyValue (Object)].
Returns:
true If the object satisfy the filter criteria.

pass

public boolean pass(Object obj)
Description copied from interface: Filter
Apply the filter to the given object.

Specified by:
pass in interface Filter
Parameters:
obj - An object to be evaluated.
Returns:
true If the object satisfy the filter criteria.

executeBeanShellScript

protected Object executeBeanShellScript(String beanShellScript,
                                        Map context)
                                 throws bsh.EvalError
Executes a BeanShell script.

Parameters:
beanShellScript - The script to execute in BeanShell format.
context - A map of arguments to be passed to the script.
Returns:
The script may return any object as result.
Throws:
bsh.EvalError

compare

public int compare(Comparable o1,
                   Comparable o2,
                   int ordering)
Compares two comparable objects.

Parameters:
ordering: - 1=ascending, -1=descending

cloneFilter

public FilterByCriteria cloneFilter()
Description copied from interface: FilterByCriteria
Create an exact copy of this filter instance.

Specified by:
cloneFilter in interface FilterByCriteria

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

formatForDisplay

protected abstract String formatForDisplay(String propertyId,
                                           Object value)
Format a given property value as displayed for the the user.

Parameters:
propertyId - The property identifier.
value - The value to format.

formatForComparison

protected abstract String formatForComparison(String propertyId,
                                              Object value)
Format a given property value valid for string comparfison against other values.

Parameters:
propertyId - The property identifier.
value - The value to format.

getPropertyValue

protected abstract Object getPropertyValue(String propertyId,
                                           Object obj)
Retrieve the value for a given property.

Parameters:
propertyId - The property to search value for.
obj - The object instance to ask for.
Returns:
The value.

Dashboard Builder Commons 6.0.0.Beta4

Copyright © 2012-2013 JBoss by Red Hat. All Rights Reserved.