Class StringPattern
- java.lang.Object
-
- org.codehaus.commons.compiler.util.StringPattern
-
public class StringPattern extends java.lang.ObjectImplementation of a UNIX shell-like string pattern algorithm.Additionally, the concept of the "combined pattern" is supported (see
matches(StringPattern[], String).
-
-
Field Summary
Fields Modifier and Type Field Description static intEXCLUDEstatic intINCLUDEstatic StringPattern[]PATTERNS_ALLAStringPatternthat matches any subject.static StringPattern[]PATTERNS_NONEAStringPatternthat matches no subject whatsoever.
-
Constructor Summary
Constructors Constructor Description StringPattern(int mode, java.lang.String pattern)StringPattern(java.lang.String pattern)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intgetMode()booleanmatches(java.lang.String text)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 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, java.lang.String text)Matchs a giventextagainst an array ofStringPatterns (which was typically created byparseCombinedPattern(String).static StringPattern[]parseCombinedPattern(java.lang.String combinedPattern)Parses a "combined pattern" into an array ofStringPatterns.java.lang.StringtoString()
-
-
-
Field Detail
-
INCLUDE
public static final int INCLUDE
-
EXCLUDE
public static final int EXCLUDE
-
PATTERNS_ALL
public static final StringPattern[] PATTERNS_ALL
AStringPatternthat matches any subject.
-
PATTERNS_NONE
public static final StringPattern[] PATTERNS_NONE
AStringPatternthat matches no subject whatsoever.
-
-
Method Detail
-
getMode
public int getMode()
- Returns:
- Whether this
StringPatternrepresents inclusion (INCLUDE) or exclusion exclusion (EXCLUDE) of subjects
-
matches
public boolean matches(java.lang.String text)
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
public static StringPattern[] parseCombinedPattern(java.lang.String combinedPattern)
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
public static boolean matches(StringPattern[] patterns, java.lang.String text)
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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-