Class WildcardPatternMatcher


public abstract class WildcardPatternMatcher extends Object
Matches simple wildcard patterns. A wildcard pattern is any combination of '*' and textual values. For example, some patterns would include:
  • "" Match none
  • "*" Match all
  • "prefix*" Prefix match
  • "*suffix" Suffix match
  • "prefix*suffix" Prefix and suffix match
  • "*infix*" Infix match
  • "prefix*infix*" Prefix and infix match
  • "*infix*suffix" Infix and suffix match
  • "prefix*infix*suffix" Prefix, infix, and suffix match
  • "exact_value" Exact match

Any consecutive sequence of '*' are combined into a single '*'.

All matchers are thread-safe.

WildcardPatternMatcher are measured typically 2 to 100 times as fast as Pattern, and have been measured up to 2000 times as fast in contrived scenarios (suffix match on long strings), and should never be slower in their limited use-case domain.

TODO: Support "**" as an escape for literal '*' in matching? No longer collapse adjacent '*'?

AO Industries, Inc.
  • Method Details

    • matchNone

      public static WildcardPatternMatcher matchNone()
      Gets the match none matcher.
    • matchAll

      public static WildcardPatternMatcher matchAll()
      Gets the match all matcher.
    • compile

      public static WildcardPatternMatcher compile(String patterns)
      Gets the matcher for the comma and/or space separated patterns.

      Any null or empty pattern matches none.

      TODO: New optional flag to limit the matchers to disable the infix matching. The prefix and suffix matches will always be fast O(n), but the infix matching can be O(n^2). This may be useful with public facing search forms, for example.

    • isEmpty

      public boolean isEmpty()
      Checks if this is empty (has no patterns). Any empty matcher does not match anything.
    • isMatch

      public abstract boolean isMatch(String input)