JIDE 3.5.15

com.jidesoft.filter
Class RegexFilter<T>

java.lang.Object
  extended by com.jidesoft.filter.AbstractFilter<T>
      extended by com.jidesoft.filter.RegexFilter<T>
All Implemented Interfaces:
Filter<T>, ObjectGrouperSupport, Serializable, Cloneable
Direct Known Subclasses:
LikeFilter, WildcardFilter

public class RegexFilter<T>
extends AbstractFilter<T>

A filter implements filtering a string based the regular expression as defined in Java Pattern class.

See Also:
Serialized Form

Field Summary
protected  boolean _beginWith
           
protected  Pattern _regex
           
 
Fields inherited from interface com.jidesoft.filter.Filter
ALL, CUSTOM, NULL, SEPARATOR
 
Constructor Summary
RegexFilter()
           
RegexFilter(String pattern)
           
 
Method Summary
protected  String convertElementToString(T value)
          Converts an element to String.
protected  String convertFromPatternToRegex(String pattern)
          Converts the input pattern to the pattern used in Java Pattern class.
protected  Pattern createRegexPattern()
          Creates regex pattern to search.
 boolean equals(Object obj)
           
 String getPattern()
          Gets the pattern string.
 String getPreference(Class<?> clazz, ConverterContext converterContext)
          Gets the preference while persisting this filter.
 boolean isBeginWith()
          Checks if the filter only matches the pattern from the beginning of the string.
 boolean isCaseSensitive()
          Checks if the filter is case sensitive.
 boolean isEndWith()
          Checks if the filter only matches the pattern from the end of the string.
 boolean isValueFiltered(T value)
          Checks to see if the value should be filtered.
 void setBeginWith(boolean beginWith)
          Sets the begingWidth flag.
 void setCaseSensitive(boolean caseSensitive)
          Sets the case sensitive.
 void setEndWith(boolean endWith)
          Sets the endWith flag.
 void setPattern(String pattern)
          Sets the pattern.
 Object[] setPreference(String prefString, Class<?> clazz, ConverterContext converterContext)
          Sets the preference to load the preference string back to this filter.
 boolean stricterThan(Filter inputFilter)
          Check if this filter is stricter than the input filter while the two filters are with the same class.
 
Methods inherited from class com.jidesoft.filter.AbstractFilter
addFilterListener, clone, fireFilterChanged, fireFilterContentChanged, fireFilterDisabled, fireFilterEnabled, fireFilterNameChanged, getConditionString, getFilterFactory, getFilterFactoryName, getFilterListeners, getName, getObjectGrouper, getObjectGrouperName, isEnabled, isFilterValid, removeFilterListener, setEnabled, setFilterFactory, setFilterFactoryName, setName, setObjectGrouper, setObjectGrouperName
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_regex

protected Pattern _regex

_beginWith

protected boolean _beginWith
Constructor Detail

RegexFilter

public RegexFilter()

RegexFilter

public RegexFilter(String pattern)
Method Detail

isValueFiltered

public boolean isValueFiltered(T value)
Description copied from interface: Filter
Checks to see if the value should be filtered.

Parameters:
value - the value to filter
Returns:
true if the value should be filtered. Otherwise false.

createRegexPattern

protected Pattern createRegexPattern()
Creates regex pattern to search.

Returns:
the regex pattern.
Since:
3.3.5

convertElementToString

protected String convertElementToString(T value)
Converts an element to String. By default we will use ObjectConverterManager.toString(value) to convert.

Parameters:
value - the element to be filtered.
Returns:
the String version of the value.

convertFromPatternToRegex

protected String convertFromPatternToRegex(String pattern)
Converts the input pattern to the pattern used in Java Pattern class.

Parameters:
pattern - the input pattern.
Returns:
the pattern string used by Pattern.

setPattern

public void setPattern(String pattern)
Sets the pattern.

Parameters:
pattern - the new pattern.
See Also:
Pattern

getPattern

public String getPattern()
Gets the pattern string.

Returns:
the pattern string.

isCaseSensitive

public boolean isCaseSensitive()
Checks if the filter is case sensitive.

Returns:
true if case sensitive. Otherwise false.

setCaseSensitive

public void setCaseSensitive(boolean caseSensitive)
Sets the case sensitive.

Parameters:
caseSensitive - true or false.

isBeginWith

public boolean isBeginWith()
Checks if the filter only matches the pattern from the beginning of the string.

Returns:
true or false.

setBeginWith

public void setBeginWith(boolean beginWith)
Sets the begingWidth flag. If true, the filter will match the pattern from the beginning of the string. Note that if both begingWith and endWith flag are true, it means "match exactly". If both flags are false, it means "match anywhere".

Parameters:
beginWith - true or false.

isEndWith

public boolean isEndWith()
Checks if the filter only matches the pattern from the end of the string.

Returns:
true or false.

setEndWith

public void setEndWith(boolean endWith)
Sets the endWith flag. If true, the filter will match the pattern from the end of the string.

Parameters:
endWith - true or false.

stricterThan

public boolean stricterThan(Filter inputFilter)
Check if this filter is stricter than the input filter while the two filters are with the same class.

Since we don't have a good algorithm to parse the regular expression, so far we just take it as a normal String.

Specified by:
stricterThan in interface Filter<T>
Overrides:
stricterThan in class AbstractFilter<T>
Parameters:
inputFilter - the input filter
Returns:
true if the pattern string in this filter contains the patter string in the input filter. Otherwise false.

equals

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

getPreference

public String getPreference(Class<?> clazz,
                            ConverterContext converterContext)
Description copied from interface: Filter
Gets the preference while persisting this filter.

Specified by:
getPreference in interface Filter<T>
Overrides:
getPreference in class AbstractFilter<T>
Parameters:
clazz - the class type to convert the values inside the filter to string
converterContext - the converter context to convert the values inside the filter to string
Returns:
the preference string.

setPreference

public Object[] setPreference(String prefString,
                              Class<?> clazz,
                              ConverterContext converterContext)
Description copied from interface: Filter
Sets the preference to load the preference string back to this filter.

Specified by:
setPreference in interface Filter<T>
Overrides:
setPreference in class AbstractFilter<T>
Parameters:
prefString - the preference string
clazz - the class type to convert the values inside the filter to string
converterContext - the converter context to convert the values inside the filter to string
Returns:
the object array to be passed into the FilterFactoryManager if necessary.

JIDE 3.5.15