Groovy Documentation

org.codenarc.util
[Groovy] Class WildcardPattern

java.lang.Object
  org.codenarc.util.WildcardPattern

class WildcardPattern

Represents a string pattern that may optionally include wildcards ('*', '**' or '?'), and provides an API to determine whether that pattern matches a specified input string.

The wildcard character '*' within the pattern matches a sequence of zero or more characters within a single file or directory name in the input string. It does not match a sequence of two or more dir/file names. For instance, 'a*b' matches 'a12345b' and 'ab', but does NOT match 'a/b' or 'a123/b'.

The '**' wildcard matches any sequence of zero or more characters in the input string, including directory names and separators . It matches any part of the directory tree. For instance, 'a**b' matches 'a12345b', 'ab', 'a/b' and 'a1/a2/a3b'.

The wildcard character '?' within the pattern matches exactly one character in the input string, excluding the normalized file separator character ('/').

This is an internal class and its API is subject to change.

Authors:
Chris Mair
Version:
\$Revision: 604 \$ - \$Date: 2011-02-09 15:53:52 -0500 (Wed, 09 Feb 2011) \$


Constructor Summary
WildcardPattern(String patternString, boolean defaultMatches = true)

Construct a new WildcardPattern instance on a single pattern or a comma-separated list of patterns.

 
Method Summary
boolean matches(String string)

Return true if the specified String matches the pattern or if the original patternString (specified in the constructor) was null or empty and the value for defaultMatches (also specified in the constructor) was true.

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Constructor Detail

WildcardPattern

WildcardPattern(String patternString, boolean defaultMatches = true)
Construct a new WildcardPattern instance on a single pattern or a comma-separated list of patterns.
Parameters:
patternString - - the pattern string, optionally including wildcard characters ('*' or '?'); may optionally contain more than one pattern, separated by commas; may be null or empty to always match
defaultMatches - - a boolean indicating whether matches() should return true if the pattern string is either empty or null. This parameter is optional and defaults to true.


 
Method Detail

matches

boolean matches(String string)
Return true if the specified String matches the pattern or if the original patternString (specified in the constructor) was null or empty and the value for defaultMatches (also specified in the constructor) was true.
Parameters:
string - - the String to check
Returns:
true if the String matches the pattern


 

Groovy Documentation