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 that clients can override if they wish.

Since:
3.3
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The default set of match rules as used by the no-argument constructor.
    static final int
    Match rule: The search pattern is blank.
    static final int
    Match rule: The search pattern contains a Camel Case expression.
    static final int
    Match rule: The search pattern matches the search result only if cases are the same.
    static final int
    Match rule: The search pattern matches exactly the search result, that is, the source of the search result equals the search pattern.
    static final int
    Match rule: The search pattern contains one or more wild cards ('*' or '?').
    static final int
    Match rule: The search pattern is a prefix of the search result.
    static final int
    Match rule: The search pattern is a string placed anywhere in the search result.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new instance of SearchPattern with default set of rules configured.
    SearchPattern(int allowedRules)
    Creates a search pattern with a rule or rules to apply for matching index keys.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Tells whether the given SearchPattern equals this pattern.
    Gets the initial (input) string pattern.
    final int
    Returns the active rule to apply for matching keys, based on the currently set pattern and allowed rules passed to the constructor.
    Gets string pattern used by matcher.
    protected boolean
    isNameCharAllowed(char nameChar)
    Checks character of element's name is allowed for specified set.
    protected boolean
    isPatternCharAllowed(char patternChar)
    Checks pattern's character is allowed for specified set.
    boolean
    Tells whether the given SearchPattern is a sub-pattern of this pattern.
    protected boolean
    Checks if character is a valid camelCase character.
    boolean
    Matches text with pattern.
    void
    setPattern(String stringPattern)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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:
    • RULE_PREFIX_MATCH

      public static final int RULE_PREFIX_MATCH
      Match rule: The search pattern is a prefix of the search result.
      See Also:
    • 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.

      Unless the pattern ends with ' ' or '>', search is performed as if '*' was specified at the end of the pattern.

      When RULE_SUBSTRING_MATCH is 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_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:
    • RULE_BLANK_MATCH

      public static final int RULE_BLANK_MATCH
      Match rule: The search pattern is blank.
      See Also:
    • RULE_CAMELCASE_MATCH

      public static final int RULE_CAMELCASE_MATCH
      Match rule: The search pattern contains a Camel Case expression.
      Examples:
      • NPE type string pattern will match NullPointerException and NpPermissionException types,
      • NuPoEx type string pattern will only match NullPointerException type.

      Can be combined with RULE_PREFIX_MATCH match rule. For example, when prefix match rule is combined with Camel Case match rule, "nPE" pattern will match nPException.
      Match rule RULE_PATTERN_MATCH may 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 with N*P*E* string pattern, it will use only Pattern match rule.

      Unless RULE_SUBSTRING_MATCH is 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_MATCH
      Match 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_RULES
      The default set of match rules as used by the no-argument constructor.
      Since:
      3.128
      See Also:
  • Constructor Details

  • Method Details

    • getPattern

      public String getPattern()
      Gets string pattern used by matcher.
      Returns:
      pattern
    • getInitialPattern

      public String getInitialPattern()
      Gets the initial (input) string pattern.
      Returns:
      pattern
      Since:
      3.128
    • setPattern

      public void setPattern(String stringPattern)
      Parameters:
      stringPattern - The stringPattern to set.
    • matches

      public boolean matches(String text)
      Matches text with pattern. The way of matching is determined by the current pattern setup - see getMatchRule() for details.

      The default implementation generally does only case-insensitive searches, i.e. RULE_CASE_SENSITIVE is 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 set pattern and allowed rules passed to the constructor.
      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

      public boolean equalsPattern(SearchPattern pattern)
      Tells whether the given SearchPattern equals 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 given SearchPattern is a sub-pattern of this pattern.

      WARNING: This method is not defined in reading order, i.e. a.isSubPattern(b) is true iff b is a sub-pattern of a, and not vice-versa.

      Parameters:
      pattern - pattern to be checked
      Returns:
      true if the given pattern is a sub pattern of this search pattern