Class StringPattern
java.lang.Object
org.codehaus.commons.compiler.util.StringPattern
Implementation of a UNIX shell-like string pattern algorithm.
Additionally, the concept of the "combined pattern" is supported (see matches(StringPattern[], String)
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
private final int
private final String
static final StringPattern[]
AStringPattern
that matches any subject.static final StringPattern[]
AStringPattern
that matches no subject whatsoever. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
getMode()
boolean
Matches the giventext
against the pattern represented by the current instance, as follows: A*
in the pattern matches any sequence of zero or more characters in thetext
A?
in the pattern matches exactly one character in thetext
Any other character in the pattern must appear exactly as it is in thetext
static boolean
matches
(StringPattern[] patterns, String text) Matchs a giventext
against an array ofStringPattern
s (which was typically created byparseCombinedPattern(String)
.static StringPattern[]
parseCombinedPattern
(String combinedPattern) Parses a "combined pattern" into an array ofStringPattern
s.toString()
private static boolean
-
Field Details
-
INCLUDE
public static final int INCLUDE- See Also:
-
EXCLUDE
public static final int EXCLUDE- See Also:
-
mode
private final int mode -
pattern
-
PATTERNS_ALL
AStringPattern
that matches any subject. -
PATTERNS_NONE
AStringPattern
that matches no subject whatsoever.
-
-
Constructor Details
-
Method Details
-
getMode
public int getMode()- Returns:
- Whether this
StringPattern
represents inclusion (INCLUDE
) or exclusion exclusion (EXCLUDE
) of subjects
-
matches
Matches the giventext
against the pattern represented by the current instance, as follows:-
A
*
in the pattern matches any sequence of zero or more characters in thetext
-
A
?
in the pattern matches exactly one character in thetext
-
Any other character in the pattern must appear exactly as it is in the
text
Notice: The
mode
flag of the current instance does not take any effect here. -
A
-
parseCombinedPattern
Parses a "combined pattern" into an array ofStringPattern
s. A combined pattern string is structured as follows:combined-pattern := [ '+' | '-' ] pattern { ( '+' | '-' ) pattern }
If a pattern is preceeded with a '-', then the
StringPattern
is created with modeEXCLUDE
, otherwise with modeINCLUDE
. -
matches
Matchs a giventext
against an array ofStringPattern
s (which was typically created byparseCombinedPattern(String)
.The last matching pattern takes effect; if its mode is
INCLUDE
, thentrue
is returned, if its mode isEXCLUDE
, thenfalse
is returned.If
patterns
isPATTERNS_NONE
, or empty, or none of its patterns matches, thenfalse
is returned.If
patterns
isPATTERNS_ALL
, thentrue
is returned.For backwards compatibility,
null
patterns are treated likePATTERNS_NONE
. -
toString
-
wildmatch
-