class PatternWithGroups extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
PatternWithGroups.EmptyStringMatchResult |
private class |
PatternWithGroups.GroupIndexMatchResult |
| Modifier and Type | Field and Description |
|---|---|
(package private) 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 String |
regex
The regular expression for matching and obtaining capturing group values.
|
private Pattern |
regexPattern
The compiled regular expression of
#regex. |
| Modifier | Constructor and Description |
|---|---|
protected |
PatternWithGroups()
Construct an empty pattern.
|
(package private) |
PatternWithGroups(Pattern regexPattern)
Construct a new pattern.
|
(package private) |
PatternWithGroups(Pattern regexPattern,
int[] groupIndexes)
Construct a new pattern.
|
(package private) |
PatternWithGroups(String regex)
Construct a new pattern.
|
(package private) |
PatternWithGroups(String regex,
int[] groupIndexes)
Construct a new pattern.
|
| Modifier and Type | Method and Description |
|---|---|
private static Pattern |
compile(String regex) |
boolean |
equals(Object obj) |
(package private) int[] |
getGroupIndexes()
Get the group indexes.
|
(package private) String |
getRegex()
Get the regular expression.
|
int |
hashCode() |
(package private) MatchResult |
match(CharSequence cs)
Match against the pattern.
|
(package private) boolean |
match(CharSequence cs,
List<String> groupValues)
Match against the pattern.
|
(package private) boolean |
match(CharSequence cs,
List<String> groupNames,
Map<String,String> groupValues)
Match against the pattern.
|
String |
toString() |
private static final int[] EMPTY_INT_ARRAY
static final PatternWithGroups EMPTY
private final String regex
private final Pattern regexPattern
#regex.private final int[] groupIndexes
private static final PatternWithGroups.EmptyStringMatchResult EMPTY_STRING_MATCH_RESULT
protected PatternWithGroups()
PatternWithGroups(String regex) throws 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.PatternSyntaxException - if the regular expression could not be compiledPatternWithGroups(String regex, int[] groupIndexes) throws 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.PatternSyntaxException - if the regular expression could not be compiledPatternWithGroups(Pattern regexPattern) throws IllegalArgumentException
regexPattern - the regular expression patternIllegalArgumentException - if the regexPattern is null.PatternWithGroups(Pattern regexPattern, int[] groupIndexes) throws IllegalArgumentException
regexPattern - the regular expression patterngroupIndexes - the array of group indexes to capturing groups.IllegalArgumentException - if the regexPattern is null.private static Pattern compile(String regex) throws PatternSyntaxException
PatternSyntaxExceptionfinal String getRegex()
final int[] getGroupIndexes()
final MatchResult match(CharSequence cs)
cs - the char sequence to match against the template.final boolean match(CharSequence cs, List<String> groupValues) throws IllegalArgumentException
If a matched then the capturing group values (if any) will be added to a list passed in as parameter.
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.IllegalArgumentException - if the group values is null.final boolean match(CharSequence cs, List<String> groupNames, Map<String,String> groupValues) throws IllegalArgumentException
If a matched then the capturing group values (if any) will be added to a list passed in as parameter.
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.IllegalArgumentException - if group values is null.Copyright © 2014 Sven Strittmatter. All Rights Reserved.