com.xmlmind.util
Class GlobMatcher

java.lang.Object
  extended by com.xmlmind.util.GlobMatcher

public final class GlobMatcher
extends java.lang.Object

Matches a glob pattern (as used by Unix shells) against an input string.

This class is not thread-safe.


Field Summary
 java.lang.String globPattern
          The string representation of the glob pattern.
 java.util.regex.Matcher matcher
          The underlying java.util.regex.Matcher.
 
Constructor Summary
GlobMatcher(java.lang.String globPattern)
          Constructs a glob pattern matcher.
 
Method Summary
static boolean containsGlobChar(java.lang.String string, boolean includingTilde)
          Convenience method: returns true if specified string contains a special character ('?', '*', '[', '{'); returns false otherwise.
static GlobMatcher create(java.lang.String globPattern)
          Convenience method: creates a matcher for specified pattern, but unlike the constructor, this method does not raise an exception if this fails.
 boolean equals(java.lang.Object other)
           
 int hashCode()
           
 boolean matches(java.lang.String string)
          Matches this glob pattern against specified string.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

globPattern

public final java.lang.String globPattern
The string representation of the glob pattern.


matcher

public final java.util.regex.Matcher matcher
The underlying java.util.regex.Matcher.

Constructor Detail

GlobMatcher

public GlobMatcher(java.lang.String globPattern)
            throws java.util.regex.PatternSyntaxException
Constructs a glob pattern matcher.

Parameters:
globPattern - the glob pattern
Throws:
java.util.regex.PatternSyntaxException - if specified glob pattern cannot be compiled into a java.util.regex.Pattern
Method Detail

matches

public boolean matches(java.lang.String string)
Matches this glob pattern against specified string.

Parameters:
string - string to be matched against this glob pattern
Returns:
true if specified string (in its entirety) matches this glob pattern; false otherwise

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

create

public static GlobMatcher create(java.lang.String globPattern)
Convenience method: creates a matcher for specified pattern, but unlike the constructor, this method does not raise an exception if this fails. Instead, this method returns null.


containsGlobChar

public static boolean containsGlobChar(java.lang.String string,
                                       boolean includingTilde)
Convenience method: returns true if specified string contains a special character ('?', '*', '[', '{'); returns false otherwise. If includingTilde is true, then '~' must also be considered as being a special character.