Package com.aoindustries.util
Class WildcardPatternMatcher
- java.lang.Object
-
- com.aoindustries.util.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.
WildcardPatternMatcherare measured typically 2 to 100 times as fast asPattern, 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 '*'?
- Author:
- AO Industries, Inc.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static WildcardPatternMatchercompile(String patterns)Gets the matcher for the comma and/or space separated patterns.booleanisEmpty()Checks if this is empty (has no patterns).abstract booleanisMatch(String input)static WildcardPatternMatchermatchAll()Gets the match all matcher.static WildcardPatternMatchermatchNone()Gets the match none matcher.
-
-
-
Method Detail
-
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)
-
-