jodd.util
Class Wildcard

java.lang.Object
  extended by jodd.util.Wildcard

public class Wildcard
extends java.lang.Object

Checks 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
protected static java.lang.String PATH_MATCH
           
protected static java.lang.String PATH_SEPARATORS
           
 
Constructor Summary
Wildcard()
           
 
Method Summary
static boolean equalsOrMatch(java.lang.String string, java.lang.String pattern)
          Checks if two strings are equals or if they match(String, String).
static boolean match(java.lang.String string, java.lang.String pattern)
          Checks whether a string matches a given wildcard pattern.
static int matchOne(java.lang.String src, java.lang.String[] patterns)
          Matches string to at least one pattern.
static boolean matchPath(java.lang.String path, java.lang.String pattern)
          Matches path against pattern using *, ?
static int matchPathOne(java.lang.String path, java.lang.String[] patterns)
          Matches path to at least one pattern.
protected static boolean matchTokens(java.lang.String[] tokens, java.lang.String[] patterns)
          Match tokenized string and pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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
Constructor Detail

Wildcard

public Wildcard()
Method Detail

match

public static boolean match(java.lang.String string,
                            java.lang.String pattern)
Checks whether a string matches a given wildcard pattern.

Parameters:
string - input string
pattern - pattern to match
Returns:
true if string matches the pattern, otherwise false

equalsOrMatch

public static boolean equalsOrMatch(java.lang.String string,
                                    java.lang.String pattern)
Checks if two strings are equals or if they match(String, String). 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 -1 otherwise.

See Also:
match(String, String)

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 -1 otherwise.

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.



Copyright © 2003-2012 Jodd Team