public class PatternWithGroups
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
PatternWithGroups.EmptyStringMatchResult |
private class |
PatternWithGroups.GroupIndexMatchResult |
Modifier and Type | Field and Description |
---|---|
static PatternWithGroups |
EMPTY
The empty pattern that matches the null or empty string.
|
private static int[] |
EMPTY_INT_ARRAY |
private static PatternWithGroups.EmptyStringMatchResult |
EMPTY_STRING_MATCH_RESULT |
private int[] |
groupIndexes
The array of group indexes to capturing groups.
|
private java.lang.String |
regex
The regular expression for matching and obtaining capturing group values.
|
private java.util.regex.Pattern |
regexPattern
The compiled regular expression of
regex . |
Modifier | Constructor and Description |
---|---|
protected |
PatternWithGroups()
Construct an empty pattern.
|
|
PatternWithGroups(java.util.regex.Pattern regexPattern)
Construct a new pattern.
|
|
PatternWithGroups(java.util.regex.Pattern regexPattern,
int[] groupIndexes)
Construct a new pattern.
|
|
PatternWithGroups(java.lang.String regex)
Construct a new pattern.
|
|
PatternWithGroups(java.lang.String regex,
int[] groupIndexes)
Construct a new pattern.
|
Modifier and Type | Method and Description |
---|---|
private static java.util.regex.Pattern |
compile(java.lang.String regex) |
boolean |
equals(java.lang.Object obj) |
int[] |
getGroupIndexes()
Get the group indexes to capturing groups.
|
java.lang.String |
getRegex()
Get the regular expression.
|
int |
hashCode() |
java.util.regex.MatchResult |
match(java.lang.CharSequence cs)
Match against the pattern.
|
boolean |
match(java.lang.CharSequence cs,
java.util.List<java.lang.String> groupValues)
Match against the pattern.
|
boolean |
match(java.lang.CharSequence cs,
java.util.List<java.lang.String> groupNames,
java.util.Map<java.lang.String,java.lang.String> groupValues)
Match against the pattern.
|
java.lang.String |
toString() |
private static final int[] EMPTY_INT_ARRAY
public static final PatternWithGroups EMPTY
private final java.lang.String regex
private final java.util.regex.Pattern regexPattern
regex
.private final int[] groupIndexes
private static final PatternWithGroups.EmptyStringMatchResult EMPTY_STRING_MATCH_RESULT
protected PatternWithGroups()
public PatternWithGroups(java.lang.String regex) throws java.util.regex.PatternSyntaxException
regex
- the regular expression. If the expression is null
or an empty string then the pattern will only match
a null
or empty string.java.util.regex.PatternSyntaxException
- if the regular expression could not be compiled.public PatternWithGroups(java.lang.String regex, int[] groupIndexes) throws java.util.regex.PatternSyntaxException
regex
- the regular expression. If the expression is null
or an empty string then the pattern will
only
match
a null
or empty string.groupIndexes
- the array of group indexes to capturing groups.java.util.regex.PatternSyntaxException
- if the regular expression could not be compiled.public PatternWithGroups(java.util.regex.Pattern regexPattern) throws java.lang.IllegalArgumentException
regexPattern
- the regular expression pattern.java.lang.IllegalArgumentException
- if the regexPattern is null
.public PatternWithGroups(java.util.regex.Pattern regexPattern, int[] groupIndexes) throws java.lang.IllegalArgumentException
regexPattern
- the regular expression pattern.groupIndexes
- the array of group indexes to capturing groups.java.lang.IllegalArgumentException
- if the regexPattern is null
.private static java.util.regex.Pattern compile(java.lang.String regex) throws java.util.regex.PatternSyntaxException
java.util.regex.PatternSyntaxException
public final java.lang.String getRegex()
public final int[] getGroupIndexes()
Any nested capturing groups will be ignored and the the group index will refer to the top-level capturing groups associated with the templates variables.
public final java.util.regex.MatchResult match(java.lang.CharSequence cs)
cs
- the char sequence to match against the template.public final boolean match(java.lang.CharSequence cs, java.util.List<java.lang.String> groupValues) throws java.lang.IllegalArgumentException
cs
- the char sequence to match against the template.groupValues
- the list to add the values of a pattern's capturing groups if matching is successful. The values are
added in the same order as the pattern's capturing groups. The list is cleared before values are added.true
if the char sequence matches the pattern, otherwise false
.java.lang.IllegalArgumentException
- if the group values is null
.public final boolean match(java.lang.CharSequence cs, java.util.List<java.lang.String> groupNames, java.util.Map<java.lang.String,java.lang.String> groupValues) throws java.lang.IllegalArgumentException
cs
- the char sequence to match against the template.groupNames
- the list names associated with a pattern's capturing groups. The names MUST be in the same order as the
pattern's capturing groups and the size MUST be equal to or less than the number of capturing groups.groupValues
- the map to add the values of a pattern's capturing groups if matching is successful. A values is put
into the map using the group name associated with the capturing group. The map is cleared before values
are added.true
if the matches the pattern, otherwise false
.java.lang.IllegalArgumentException
- if group values is null
.public final int hashCode()
hashCode
in class java.lang.Object
public final boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public final java.lang.String toString()
toString
in class java.lang.Object