com.springsource.bundlor.util
Class MatchUtils

java.lang.Object
  extended by com.springsource.bundlor.util.MatchUtils

public final class MatchUtils
extends java.lang.Object

Wildcard package matching utils.

Concurrent Semantics
Threadsafe.

Author:
Rob Harrop

Field Summary
private static java.lang.String DOT_WILDCARD
           
static int NO_MATCH
          Indicates that no match was found.
private static java.lang.String PACKAGE_SEPARATOR
           
private static java.lang.String REGEX_ESCAPED_PACKAGE_SEPARATOR
           
private static java.lang.String REGEX_OPTIONAL_DOT_WILDCARD
          Pattern to match on optional following package segments: com.foo.* -> com.foo.bar
private static java.lang.String REGEX_OPTIONAL_WILDCARD
           
private static java.lang.String REGEX_WILDCARD
           
private static java.lang.String WILDCARD
           
 
Constructor Summary
MatchUtils()
           
 
Method Summary
static boolean matches(java.lang.String candidate, java.lang.String pattern)
          Tests whether candidate matches the supplied pattern.
static int rankedMatch(java.lang.String candidate, java.lang.String pattern)
          Performs a ranked match between the candidate package and the supplied pattern.
private static java.lang.String stripWildcard(java.lang.String pattern)
          Strips the wildcard from the supplied pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_MATCH

public static final int NO_MATCH
Indicates that no match was found.

See Also:
Constant Field Values

WILDCARD

private static final java.lang.String WILDCARD
See Also:
Constant Field Values

DOT_WILDCARD

private static final java.lang.String DOT_WILDCARD
See Also:
Constant Field Values

PACKAGE_SEPARATOR

private static final java.lang.String PACKAGE_SEPARATOR
See Also:
Constant Field Values

REGEX_ESCAPED_PACKAGE_SEPARATOR

private static final java.lang.String REGEX_ESCAPED_PACKAGE_SEPARATOR
See Also:
Constant Field Values

REGEX_WILDCARD

private static final java.lang.String REGEX_WILDCARD
See Also:
Constant Field Values

REGEX_OPTIONAL_DOT_WILDCARD

private static final java.lang.String REGEX_OPTIONAL_DOT_WILDCARD
Pattern to match on optional following package segments: com.foo.* -> com.foo.bar

See Also:
Constant Field Values

REGEX_OPTIONAL_WILDCARD

private static final java.lang.String REGEX_OPTIONAL_WILDCARD
See Also:
Constant Field Values
Constructor Detail

MatchUtils

public MatchUtils()
Method Detail

matches

public static boolean matches(java.lang.String candidate,
                              java.lang.String pattern)
Tests whether candidate matches the supplied pattern.

Parameters:
candidate - the candidate.
pattern - the pattern to match against.
Returns:
true if there is a match; otherwise false.

rankedMatch

public static int rankedMatch(java.lang.String candidate,
                              java.lang.String pattern)
Performs a ranked match between the candidate package and the supplied pattern. If no match is found, the match rank is NO_MATCH. When a match is found a higher rank signifies a more specific match. For example, com.foo.bar.* is a more specific match against com.foo.bar.Fudge than com.foo.*.

Parameters:
candidate - the candidate package.
pattern - the package pattern.
Returns:
the match rank.

stripWildcard

private static java.lang.String stripWildcard(java.lang.String pattern)
Strips the wildcard from the supplied pattern.

Parameters:
pattern - the pattern.
Returns:
the stripped pattern.