Package org.eclipse.ui.dialogs
Class SearchPattern
- java.lang.Object
-
- org.eclipse.ui.dialogs.SearchPattern
-
public class SearchPattern extends Object
A search pattern defines how search results are found.This class is intended to be subclassed by clients. A default behavior is provided for each of the methods above, that clients can override if they wish.
- Since:
- 3.3
-
-
Field Summary
Fields Modifier and Type Field Description static intRULE_BLANK_MATCHMatch rule: The search pattern is blank.static intRULE_CAMELCASE_MATCHMatch rule: The search pattern contains a Camel Case expression.static intRULE_CASE_SENSITIVEMatch rule: The search pattern matches the search result only if cases are the same.static intRULE_EXACT_MATCHMatch rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern.static intRULE_PATTERN_MATCHMatch rule: The search pattern contains one or more wild cards ('*' or '?').static intRULE_PREFIX_MATCHMatch rule: The search pattern is a prefix of the search result.
-
Constructor Summary
Constructors Constructor Description SearchPattern()Creates a new instance of SearchPattern with the following match rules configured:RULE_EXACT_MATCH|RULE_PREFIX_MATCH|RULE_PATTERN_MATCH|RULE_CAMELCASE_MATCH|RULE_BLANK_MATCH)SearchPattern(int allowedRules)Creates a search pattern with the rule to apply for matching index keys.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequalsPattern(SearchPattern pattern)Tells whether the givenSearchPatternequals this pattern.intgetMatchRule()Returns the rule to apply for matching keys.StringgetPattern()Gets string pattern used by matcherprotected 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)Check if character is valid camelCase characterbooleanmatches(String text)Matches text with pattern. matching is determine by matchKind.voidsetPattern(String stringPattern)
-
-
-
Field Detail
-
RULE_EXACT_MATCH
public static final int RULE_EXACT_MATCH
Match 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:
- Constant Field Values
-
RULE_PREFIX_MATCH
public static final int RULE_PREFIX_MATCH
Match rule: The search pattern is a prefix of the search result.- See Also:
- Constant Field Values
-
RULE_PATTERN_MATCH
public static final int RULE_PATTERN_MATCH
Match 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.- See Also:
- Constant Field Values
-
RULE_CASE_SENSITIVE
public static final int RULE_CASE_SENSITIVE
Match 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:
- Constant Field Values
-
RULE_BLANK_MATCH
public static final int RULE_BLANK_MATCH
Match rule: The search pattern is blank.- See Also:
- Constant Field Values
-
RULE_CAMELCASE_MATCH
public static final int RULE_CAMELCASE_MATCH
Match 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.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SearchPattern
public SearchPattern()
Creates a new instance of SearchPattern with the following match rules configured:RULE_EXACT_MATCH|RULE_PREFIX_MATCH|RULE_PATTERN_MATCH|RULE_CAMELCASE_MATCH|RULE_BLANK_MATCH)
-
SearchPattern
public SearchPattern(int allowedRules)
Creates a search pattern with the rule to apply for matching index keys. It can be exact match, prefix match, pattern match or camelCase match. Rule can also be combined with a case sensitivity flag.- Parameters:
allowedRules- one ofRULE_EXACT_MATCH,RULE_PREFIX_MATCH,RULE_PATTERN_MATCH,RULE_CASE_SENSITIVE,RULE_CAMELCASE_MATCHcombined with one of following values:RULE_EXACT_MATCH,RULE_PREFIX_MATCH,RULE_PATTERN_MATCHorRULE_CAMELCASE_MATCH. e.g.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.
Note also that default behavior for generic types/methods search is to find exact matches.
-
-
Method Detail
-
getPattern
public String getPattern()
Gets string pattern used by matcher- Returns:
- pattern
-
setPattern
public void setPattern(String stringPattern)
- Parameters:
stringPattern- The stringPattern to set.
-
matches
public boolean matches(String text)
Matches text with pattern. matching is determine by matchKind.- Parameters:
text- the text to match- Returns:
- true if search pattern was matched with text false in other way
-
isPatternCharAllowed
protected boolean isPatternCharAllowed(char patternChar)
Checks pattern's character is allowed for specified set. It could be override if you want 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 override if you want 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 rule to apply for matching keys. Can be exact match, prefix match, pattern match or camelcase match. Rule can also be combined with a case sensitivity flag.- Returns:
- one of RULE_EXACT_MATCH, RULE_PREFIX_MATCH, RULE_PATTERN_MATCH, RULE_CAMELCASE_MATCH, combined with RULE_CASE_SENSITIVE, e.g. RULE_EXACT_MATCH | RULE_CASE_SENSITIVE if an exact and case sensitive match is requested, or RULE_PREFIX_MATCH if a prefix non case sensitive match is requested.
-
isValidCamelCaseChar
protected boolean isValidCamelCaseChar(char ch)
Check if character is valid camelCase character- Parameters:
ch- character to be validated- Returns:
- true if character is valid
-
equalsPattern
public boolean equalsPattern(SearchPattern pattern)
Tells whether the givenSearchPatternequals this pattern.- Parameters:
pattern- pattern to be checked- Returns:
- true if the given pattern equals this search pattern
-
isSubPattern
public boolean isSubPattern(SearchPattern pattern)
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
-
-