Class PatternWithGroups
java.lang.Object
org.glassfish.tyrus.core.uri.internal.PatternWithGroups
- Direct Known Subclasses:
PathPattern
A pattern for matching a string against a regular expression and returning capturing group values for any capturing
groups present in the expression.
- Author:
- Paul Sandoz, Gerard Davison (gerard.davison at oracle.com)
-
Field Summary
Modifier and TypeFieldDescriptionstatic final PatternWithGroups
The empty pattern that matches the null or empty string. -
Constructor Summary
ModifierConstructorDescriptionprotected
Construct an empty pattern.PatternWithGroups
(String regex) Construct a new pattern.PatternWithGroups
(String regex, int[] groupIndexes) Construct a new pattern.PatternWithGroups
(Pattern regexPattern) Construct a new pattern.PatternWithGroups
(Pattern regexPattern, int[] groupIndexes) Construct a new pattern. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
final int[]
Get the group indexes to capturing groups.final String
getRegex()
Get the regular expression.final int
hashCode()
final MatchResult
match
(CharSequence cs) Match against the pattern.final boolean
match
(CharSequence cs, List<String> groupValues) Match against the pattern.final boolean
Match against the pattern.final String
toString()
-
Field Details
-
EMPTY
The empty pattern that matches the null or empty string.
-
-
Constructor Details
-
PatternWithGroups
protected PatternWithGroups()Construct an empty pattern. -
PatternWithGroups
Construct a new pattern.- Parameters:
regex
- the regular expression. If the expression isnull
or an empty string then the pattern will only match anull
or empty string.- Throws:
PatternSyntaxException
- if the regular expression could not be compiled.
-
PatternWithGroups
Construct a new pattern.- Parameters:
regex
- the regular expression. If the expression isnull
or an empty string then the pattern will only match anull
or empty string.groupIndexes
- the array of group indexes to capturing groups.- Throws:
PatternSyntaxException
- if the regular expression could not be compiled.
-
PatternWithGroups
Construct a new pattern.- Parameters:
regexPattern
- the regular expression pattern.- Throws:
IllegalArgumentException
- if the regexPattern isnull
.
-
PatternWithGroups
Construct a new pattern.- Parameters:
regexPattern
- the regular expression pattern.groupIndexes
- the array of group indexes to capturing groups.- Throws:
IllegalArgumentException
- if the regexPattern isnull
.
-
-
Method Details
-
getRegex
Get the regular expression.- Returns:
- the regular expression.
-
getGroupIndexes
public final int[] getGroupIndexes()Get the group indexes to capturing groups.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.
- Returns:
- the group indexes to capturing groups.
-
match
Match against the pattern.- Parameters:
cs
- the char sequence to match against the template.- Returns:
- the match result, otherwise null if no match occurs.
-
match
public final boolean match(CharSequence cs, List<String> groupValues) throws IllegalArgumentException Match against the pattern.If a matched then the capturing group values (if any) will be added to a list passed in as parameter.
- Parameters:
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.- Returns:
true
if the char sequence matches the pattern, otherwisefalse
.- Throws:
IllegalArgumentException
- if the group values isnull
.
-
match
public final boolean match(CharSequence cs, List<String> groupNames, Map<String, String> groupValues) throws IllegalArgumentExceptionMatch against the pattern.If a matched then the capturing group values (if any) will be added to a list passed in as parameter.
- Parameters:
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.- Returns:
true
if the matches the pattern, otherwisefalse
.- Throws:
IllegalArgumentException
- if group values isnull
.
-
hashCode
public final int hashCode() -
equals
-
toString
-