Package jodd.util
Class Wildcard
- java.lang.Object
-
- jodd.util.Wildcard
-
public class Wildcard extends java.lang.ObjectChecks whether a string or path matches a given wildcard pattern. Possible patterns allow to match single characters ('?') or any count of characters ('*'). Wildcard characters can be escaped (by an '\'). When matching path, deep tree wildcard also can be used ('**').This method uses recursive matching, as in linux or windows. regexp works the same. This method is very fast, comparing to similar implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringPATH_MATCHprotected static java.lang.StringPATH_SEPARATORS
-
Constructor Summary
Constructors Constructor Description Wildcard()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanequalsOrMatch(java.lang.CharSequence string, java.lang.CharSequence pattern)Checks if two strings are equals or if theymatch(CharSequence, CharSequence).static booleanmatch(java.lang.CharSequence string, java.lang.CharSequence pattern)Checks whether a string matches a given wildcard pattern.static intmatchOne(java.lang.String src, java.lang.String... patterns)Matches string to at least one pattern.static booleanmatchPath(java.lang.String path, java.lang.String pattern)Matches path against pattern using *, ? and ** wildcards.static intmatchPathOne(java.lang.String path, java.lang.String... patterns)Matches path to at least one pattern.protected static booleanmatchTokens(java.lang.String[] tokens, java.lang.String[] patterns)Match tokenized string and pattern.
-
-
-
Field Detail
-
PATH_MATCH
protected static final java.lang.String PATH_MATCH
- See Also:
- Constant Field Values
-
PATH_SEPARATORS
protected static final java.lang.String PATH_SEPARATORS
- See Also:
- Constant Field Values
-
-
Method Detail
-
match
public static boolean match(java.lang.CharSequence string, java.lang.CharSequence pattern)Checks whether a string matches a given wildcard pattern.- Parameters:
string- input stringpattern- pattern to match- Returns:
trueif string matches the pattern, otherwisefalse
-
equalsOrMatch
public static boolean equalsOrMatch(java.lang.CharSequence string, java.lang.CharSequence pattern)Checks if two strings are equals or if theymatch(CharSequence, CharSequence). Useful for cases when matching a lot of equal strings and speed is important.
-
matchOne
public static int matchOne(java.lang.String src, java.lang.String... patterns)Matches string to at least one pattern. Returns index of matched pattern, or-1otherwise.- See Also:
match(CharSequence, CharSequence)
-
matchPathOne
public static int matchPathOne(java.lang.String path, java.lang.String... patterns)Matches path to at least one pattern. Returns index of matched pattern or-1otherwise.- See Also:
matchPath(String, String)
-
matchPath
public static boolean matchPath(java.lang.String path, java.lang.String pattern)Matches path against pattern using *, ? and ** wildcards. Both path and the pattern are tokenized on path separators (both \ and /). '**' represents deep tree wildcard, as in Ant.
-
matchTokens
protected static boolean matchTokens(java.lang.String[] tokens, java.lang.String[] patterns)Match tokenized string and pattern.
-
-