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 intstatic final intprivate final intprivate final Stringstatic final StringPattern[]AStringPatternthat matches any subject.static final StringPattern[]AStringPatternthat matches no subject whatsoever. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintgetMode()booleanMatches the giventextagainst the pattern represented by the current instance, as follows: A*in the pattern matches any sequence of zero or more characters in thetextA?in the pattern matches exactly one character in thetextAny other character in the pattern must appear exactly as it is in thetextstatic booleanmatches(StringPattern[] patterns, String text) Matchs a giventextagainst an array ofStringPatterns (which was typically created byparseCombinedPattern(String).static StringPattern[]parseCombinedPattern(String combinedPattern) Parses a "combined pattern" into an array ofStringPatterns.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
AStringPatternthat matches any subject. -
PATTERNS_NONE
AStringPatternthat matches no subject whatsoever.
-
-
Constructor Details
-
StringPattern
-
StringPattern
-
-
Method Details
-
getMode
public int getMode()- Returns:
- Whether this
StringPatternrepresents inclusion (INCLUDE) or exclusion exclusion (EXCLUDE) of subjects
-
matches
Matches the giventextagainst 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
modeflag of the current instance does not take any effect here. -
A
-
parseCombinedPattern
Parses a "combined pattern" into an array ofStringPatterns. A combined pattern string is structured as follows:combined-pattern := [ '+' | '-' ] pattern { ( '+' | '-' ) pattern }If a pattern is preceeded with a '-', then the
StringPatternis created with modeEXCLUDE, otherwise with modeINCLUDE. -
matches
Matchs a giventextagainst an array ofStringPatterns (which was typically created byparseCombinedPattern(String).The last matching pattern takes effect; if its mode is
INCLUDE, thentrueis returned, if its mode isEXCLUDE, thenfalseis returned.If
patternsisPATTERNS_NONE, or empty, or none of its patterns matches, thenfalseis returned.If
patternsisPATTERNS_ALL, thentrueis returned.For backwards compatibility,
nullpatterns are treated likePATTERNS_NONE. -
toString
-
wildmatch
-