Class SearchPattern
This class is intended to be subclassed by clients. A default behavior is provided that clients can override if they wish.
- Since:
- 3.3
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default set of match rules as used by the no-argument constructor.static final intMatch rule: The search pattern is blank.static final intMatch rule: The search pattern contains a Camel Case expression.static final intMatch rule: The search pattern matches the search result only if cases are the same.static final intMatch rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern.static final intMatch rule: The search pattern contains one or more wild cards ('*' or '?').static final intMatch rule: The search pattern is a prefix of the search result.static final intMatch rule: The search pattern is a string placed anywhere in the search result. -
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of SearchPattern withdefault set of rulesconfigured.SearchPattern(int allowedRules) Creates a search pattern with a rule or rules to apply for matching index keys. -
Method Summary
Modifier and TypeMethodDescriptionbooleanequalsPattern(SearchPattern pattern) Tells whether the givenSearchPatternequals this pattern.Gets the initial (input) string pattern.final intReturns the active rule to apply for matching keys, based on the currently setpatternand allowed rules passed to theconstructor.Gets string pattern used by matcher.protected booleanisNameCharAllowed(char nameChar) Checks character of element's name is allowed for specified set.protected booleanisPatternCharAllowed(char patternChar) Checks pattern's character is allowed for specified set.booleanisSubPattern(SearchPattern pattern) Tells whether the givenSearchPatternis a sub-pattern of this pattern.protected booleanisValidCamelCaseChar(char ch) Checks if character is a valid camelCase character.booleanMatches text with pattern.voidsetPattern(String stringPattern)
-
Field Details
-
RULE_EXACT_MATCH
public static final int RULE_EXACT_MATCHMatch rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern. Search pattern should start from lowerCase char.- See Also:
-
RULE_PREFIX_MATCH
public static final int RULE_PREFIX_MATCHMatch rule: The search pattern is a prefix of the search result.- See Also:
-
RULE_PATTERN_MATCH
public static final int RULE_PATTERN_MATCHMatch rule: The search pattern contains one or more wild cards ('*' or '?'). A '*' wild-card can replace 0 or more characters in the search result. A '?' wild-card replaces exactly 1 character in the search result.Unless the pattern ends with ' ' or '>', search is performed as if '*' was specified at the end of the pattern.
When
RULE_SUBSTRING_MATCHis in effect, search is performed as if '*' was specified at the start of the pattern.- See Also:
-
RULE_CASE_SENSITIVE
public static final int RULE_CASE_SENSITIVEMatch rule: The search pattern matches the search result only if cases are the same. Can be combined with previous rules, e.g.RULE_EXACT_MATCH|RULE_CASE_SENSITIVE.- See Also:
-
RULE_BLANK_MATCH
public static final int RULE_BLANK_MATCHMatch rule: The search pattern is blank.- See Also:
-
RULE_CAMELCASE_MATCH
public static final int RULE_CAMELCASE_MATCHMatch rule: The search pattern contains a Camel Case expression.
Examples:NPEtype string pattern will matchNullPointerExceptionandNpPermissionExceptiontypes,NuPoExtype string pattern will only matchNullPointerExceptiontype.
Can be combined withRULE_PREFIX_MATCHmatch rule. For example, when prefix match rule is combined with Camel Case match rule,"nPE"pattern will matchnPException.
Match ruleRULE_PATTERN_MATCHmay also be combined but both rules will not be used simultaneously as they are mutually exclusive. Used match rule depends on whether string pattern contains specific pattern characters (e.g. '*' or '?') or not. If it does, then only Pattern match rule will be used, otherwise only Camel Case match will be used. For example, with"NPE"string pattern, search will only use Camel Case match rule, but withN*P*E*string pattern, it will use only Pattern match rule.Unless
RULE_SUBSTRING_MATCHis in effect, it is required that the 1st pattern's char must match the very 1st char of the search result.- See Also:
-
RULE_SUBSTRING_MATCH
public static final int RULE_SUBSTRING_MATCHMatch rule: The search pattern is a string placed anywhere in the search result. When in effect, this flag also affects some of the other match rules (see their documentation for details).Prefix search may still be enforced by placing '>' at the beginning of the pattern. Analogically, suffix search may be enforced by placing ' ' or '<' at the end of the pattern.
- Since:
- 3.128
- See Also:
-
DEFAULT_MATCH_RULES
public static final int DEFAULT_MATCH_RULESThe default set of match rules as used by the no-argument constructor.- Since:
- 3.128
- See Also:
-
-
Constructor Details
-
SearchPattern
public SearchPattern()Creates a new instance of SearchPattern withdefault set of rulesconfigured. -
SearchPattern
public SearchPattern(int allowedRules) Creates a search pattern with a rule or rules to apply for matching index keys.- Parameters:
allowedRules- one ofRULE_EXACT_MATCH,RULE_PREFIX_MATCH,RULE_SUBSTRING_MATCH,RULE_PATTERN_MATCH,RULE_CAMELCASE_MATCH,RULE_CASE_SENSITIVE, or their combination in order to enable more types of matching. Note that rulesRULE_CASE_SENSITIVEandRULE_SUBSTRING_MATCHare special in that they generally just affect how the other match rules behave.
Examples:RULE_EXACT_MATCH|RULE_CASE_SENSITIVEif an exact and case sensitive match is requested,RULE_PREFIX_MATCHif a prefix non case sensitive match is requested, orRULE_EXACT_MATCHif a non case sensitive and erasure match is requested.
-
-
Method Details
-
getPattern
Gets string pattern used by matcher.- Returns:
- pattern
-
getInitialPattern
Gets the initial (input) string pattern.- Returns:
- pattern
- Since:
- 3.128
-
setPattern
- Parameters:
stringPattern- The stringPattern to set.
-
matches
Matches text with pattern. The way of matching is determined by the current pattern setup - seegetMatchRule()for details.The default implementation generally does only case-insensitive searches, i.e.
RULE_CASE_SENSITIVEis not considered here.- Parameters:
text- the text to match- Returns:
- true if search pattern was matched with text
-
isPatternCharAllowed
protected boolean isPatternCharAllowed(char patternChar) Checks pattern's character is allowed for specified set. It could be overridden if you want to change logic of camelCaseMatch methods.- Parameters:
patternChar- the char to check- Returns:
- true if patternChar is in set of allowed characters for pattern
-
isNameCharAllowed
protected boolean isNameCharAllowed(char nameChar) Checks character of element's name is allowed for specified set. It could be overridden if you want to change logic of camelCaseMatch methods.- Parameters:
nameChar- - name of searched element- Returns:
- if nameChar is in set of allowed characters for name of element
-
getMatchRule
public final int getMatchRule()Returns the active rule to apply for matching keys, based on the currently setpatternand allowed rules passed to theconstructor.- Returns:
- one of
RULE_BLANK_MATCH,RULE_EXACT_MATCH,RULE_PREFIX_MATCH,RULE_PATTERN_MATCH,RULE_CAMELCASE_MATCH
-
isValidCamelCaseChar
protected boolean isValidCamelCaseChar(char ch) Checks if character is a valid camelCase character.- Parameters:
ch- character to be validated- Returns:
- true if character is valid
-
equalsPattern
Tells whether the givenSearchPatternequals this pattern.- Parameters:
pattern- pattern to be checked- Returns:
- true if the given pattern equals this search pattern
-
isSubPattern
Tells whether the givenSearchPatternis a sub-pattern of this pattern.WARNING: This method is not defined in reading order, i.e.
a.isSubPattern(b)istrueiffbis a sub-pattern ofa, and not vice-versa.- Parameters:
pattern- pattern to be checked- Returns:
- true if the given pattern is a sub pattern of this search pattern
-