Package ca.odell.glazedlists.matchers
Class TextMatcherEditor<E>
- java.lang.Object
-
- ca.odell.glazedlists.matchers.AbstractMatcherEditorListenerSupport<E>
-
- ca.odell.glazedlists.matchers.AbstractMatcherEditor<E>
-
- ca.odell.glazedlists.matchers.TextMatcherEditor<E>
-
- All Implemented Interfaces:
MatcherEditor<E>
- Direct Known Subclasses:
SearchEngineTextMatcherEditor,TextComponentMatcherEditor
public class TextMatcherEditor<E> extends AbstractMatcherEditor<E>
A matcher editor that matches Objects that contain a filter text string. ThisTextMatcherEditoris not coupled with any UI component that allows the user to edit the filter text. That job is left to subclasses. This matcher editor is fully concrete, and may be used directly by headless applications.The
TextMatcherEditorrequires that either aTextFilteratorbe specified in its constructor, or that every Object to be matched implements theTextFilterableinterface. These are used to extract the searchableStrings for each Object.TextMatcherEditoris able to operate in one of three modes.CONTAINSwill produceMatcherobjects that test if at least one searchable string for an Object contains one of the filter strings anywhere within itself.STARTS_WITHwill produceMatcherobjects that test if at least one searchable string for an Object begins with at least one of the filter strings.REGULAR_EXPRESSIONwill produceMatcherobjects that test if at least one searchable string for an Object matches, using regular expression rules, at least one of the filter strings.
TextMatcherEditoris able to operate with one of two strategies.IDENTICAL_STRATEGYdefines a text match as a precise character-for-character match between the filters and the text.NORMALIZED_STRATEGYdefines a text match more leniently for Latin-character based languages. Specifically, diacritics are stripped from all Latin characters before comparisons are made. Consequently, filters like "resume" match words like "r�sum�".
- Author:
- James Lemieux, Jesse Wilson
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface ca.odell.glazedlists.matchers.MatcherEditor
MatcherEditor.Event<E>, MatcherEditor.Listener<E>
-
-
Field Summary
Fields Modifier and Type Field Description static intCONTAINSMatching mode where items are considered a match if at least one of the filter strings extracted from an object contains one of the given search strings.static intEXACTMatching mode where items are considered a match if they are an exact character for character match with at least one of the filter strings.static java.lang.ObjectIDENTICAL_STRATEGYCharacter comparison strategy that assumes all characters can be compared directly as though they are ASCII.static java.lang.ObjectNORMALIZED_STRATEGYCharacter comparison strategy that assumes all Latin characters should have their diacritical marks stripped in an effort to normalize words to their most basic form.static intREGULAR_EXPRESSIONMatching mode where items are considered a match using aMatcherproduced by compiling a regular expression intoPattern.static intSTARTS_WITHMatching mode where items are considered a match if at least one of the filter strings extracted from an object starts with one of the given search strings.
-
Constructor Summary
Constructors Constructor Description TextMatcherEditor()Creates aTextMatcherEditorwhose Matchers can test only elements which implement theTextFilterableinterface.TextMatcherEditor(TextFilterator<? super E> filterator)Creates aTextMatcherEditorthat matches Objects using the specifiedTextFilteratorto get theStrings to search.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected ca.odell.glazedlists.impl.filter.TextMatcher<E>getCurrentTextMatcher()Return the current Matcher if it is aTextMatcherornullif no current Matcher exists or is something other than aTextMatcher.TextFilterator<? super E>getFilterator()Get the filterator used to extract Strings from the matched elements.intgetMode()Returns the behaviour mode for thisTextMatcherEditor.java.lang.ObjectgetStrategy()Returns the character comparison strategy for thisTextMatcherEditor.voidsetFilterator(TextFilterator<? super E> filterator)Set the filterator used to extract Strings from the matched elements.voidsetFilterText(java.lang.String[] newFilters)Adjusts the filters of thisTextMatcherEditorand fires a change to theMatcher.voidsetMode(int mode)Modify the behaviour of thisTextMatcherEditorto one of the predefined modes.voidsetStrategy(java.lang.Object strategy)Modify the character matching strategy of thisTextMatcherEditorto one of the predefined strategies.protected voidsetTextMatcher(ca.odell.glazedlists.impl.filter.TextMatcher<E> newMatcher)This method replaces the current Matcher in this TextMatcherEditor with thenewMatcherif it is different.-
Methods inherited from class ca.odell.glazedlists.matchers.AbstractMatcherEditor
fireChanged, fireConstrained, fireMatchAll, fireMatchNone, fireRelaxed, getMatcher, isCurrentlyMatchingAll, isCurrentlyMatchingNone
-
Methods inherited from class ca.odell.glazedlists.matchers.AbstractMatcherEditorListenerSupport
addMatcherEditorListener, createChangedEvent, createConstrainedEvent, createMatchAllEvent, createMatchNoneEvent, createRelaxedEvent, fireChangedMatcher, removeMatcherEditorListener
-
-
-
-
Field Detail
-
CONTAINS
public static final int CONTAINS
Matching mode where items are considered a match if at least one of the filter strings extracted from an object contains one of the given search strings.- See Also:
- Constant Field Values
-
STARTS_WITH
public static final int STARTS_WITH
Matching mode where items are considered a match if at least one of the filter strings extracted from an object starts with one of the given search strings.- See Also:
- Constant Field Values
-
REGULAR_EXPRESSION
public static final int REGULAR_EXPRESSION
Matching mode where items are considered a match using aMatcherproduced by compiling a regular expression intoPattern.- See Also:
- Constant Field Values
-
EXACT
public static final int EXACT
Matching mode where items are considered a match if they are an exact character for character match with at least one of the filter strings.- See Also:
- Constant Field Values
-
IDENTICAL_STRATEGY
public static final java.lang.Object IDENTICAL_STRATEGY
Character comparison strategy that assumes all characters can be compared directly as though they are ASCII. This implies there is no fuzzy matching with this strategy - each character must be precisely matched.
-
NORMALIZED_STRATEGY
public static final java.lang.Object NORMALIZED_STRATEGY
Character comparison strategy that assumes all Latin characters should have their diacritical marks stripped in an effort to normalize words to their most basic form. This allows a degree of fuzziness within the matching algorithm, since words like "resume" will match similar words with diacritics like "r�sum�". This strategy is particularly useful when the text to be searched contains text like names in foreign languages, and your application would like search terms such as "Muller" to match the actual native spelling: "M�ller".
-
-
Constructor Detail
-
TextMatcherEditor
public TextMatcherEditor()
Creates aTextMatcherEditorwhose Matchers can test only elements which implement theTextFilterableinterface.The
Matchers from thisMatcherEditorwill throw aClassCastExceptionwhen called with an Object that does not implementTextFilterable.
-
TextMatcherEditor
public TextMatcherEditor(TextFilterator<? super E> filterator)
Creates aTextMatcherEditorthat matches Objects using the specifiedTextFilteratorto get theStrings to search.- Parameters:
filterator- the object that will extract filter Strings from each object in thesource;nullindicates the list elements implementTextFilterable
-
-
Method Detail
-
getFilterator
public TextFilterator<? super E> getFilterator()
Get the filterator used to extract Strings from the matched elements.
-
setFilterator
public void setFilterator(TextFilterator<? super E> filterator)
Set the filterator used to extract Strings from the matched elements.
-
setMode
public void setMode(int mode)
Modify the behaviour of thisTextMatcherEditorto one of the predefined modes.- Parameters:
mode- eitherCONTAINS,STARTS_WITH,REGULAR_EXPRESSION, orEXACT
-
getMode
public int getMode()
Returns the behaviour mode for thisTextMatcherEditor.- Returns:
- one of
CONTAINS(default),STARTS_WITH,REGULAR_EXPRESSION, orEXACT
-
setStrategy
public void setStrategy(java.lang.Object strategy)
Modify the character matching strategy of thisTextMatcherEditorto one of the predefined strategies. See the documentation for each constant in order contrast the strategies.- Parameters:
strategy- eitherIDENTICAL_STRATEGYorNORMALIZED_STRATEGY
-
getStrategy
public java.lang.Object getStrategy()
Returns the character comparison strategy for thisTextMatcherEditor. See the documentation for each constant in order contrast the strategies.- Returns:
- one of
IDENTICAL_STRATEGYorNORMALIZED_STRATEGY
-
getCurrentTextMatcher
protected ca.odell.glazedlists.impl.filter.TextMatcher<E> getCurrentTextMatcher()
Return the current Matcher if it is aTextMatcherornullif no current Matcher exists or is something other than aTextMatcher.
-
setFilterText
public void setFilterText(java.lang.String[] newFilters)
Adjusts the filters of thisTextMatcherEditorand fires a change to theMatcher.- Parameters:
newFilters- theStrings representing all of the filter values
-
setTextMatcher
protected void setTextMatcher(ca.odell.glazedlists.impl.filter.TextMatcher<E> newMatcher)
This method replaces the current Matcher in this TextMatcherEditor with thenewMatcherif it is different. If the current Matcher is also a TextMatcher then many comparisons between the two in order to determine if the new Matcher is a strict constrainment or relaxation of the current TextMatcher.- Parameters:
newMatcher- new TextMatcher which defines the text filtering logic
-
-