Package org.glassfish.jersey.uri
Class PatternWithGroups
- java.lang.Object
-
- org.glassfish.jersey.uri.PatternWithGroups
-
- Direct Known Subclasses:
PathPattern
public class PatternWithGroups extends java.lang.ObjectA pattern for matching a string against a regular expression and returning capturing group values for any capturing groups present in the expression.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classPatternWithGroups.EmptyStringMatchResultprivate classPatternWithGroups.GroupIndexMatchResult
-
Field Summary
Fields Modifier and Type Field Description static PatternWithGroupsEMPTYThe empty pattern that matches the null or empty string.private static int[]EMPTY_INT_ARRAYprivate static PatternWithGroups.EmptyStringMatchResultEMPTY_STRING_MATCH_RESULTprivate int[]groupIndexesThe array of group indexes to capturing groups.private java.lang.StringregexThe regular expression for matching and obtaining capturing group values.private java.util.regex.PatternregexPatternThe compiled regular expression ofregex.
-
Constructor Summary
Constructors Modifier Constructor Description protectedPatternWithGroups()Construct an empty pattern.PatternWithGroups(java.lang.String regex)Construct a new pattern.PatternWithGroups(java.lang.String regex, int[] groupIndexes)Construct a new pattern.PatternWithGroups(java.util.regex.Pattern regexPattern)Construct a new pattern.PatternWithGroups(java.util.regex.Pattern regexPattern, int[] groupIndexes)Construct a new pattern.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.util.regex.Patterncompile(java.lang.String regex)booleanequals(java.lang.Object obj)int[]getGroupIndexes()Get the group indexes to capturing groups.java.lang.StringgetRegex()Get the regular expression.inthashCode()java.util.regex.MatchResultmatch(java.lang.CharSequence cs)Match against the pattern.booleanmatch(java.lang.CharSequence cs, java.util.List<java.lang.String> groupValues)Match against the pattern.booleanmatch(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.StringtoString()
-
-
-
Field Detail
-
EMPTY_INT_ARRAY
private static final int[] EMPTY_INT_ARRAY
-
EMPTY
public static final PatternWithGroups EMPTY
The empty pattern that matches the null or empty string.
-
regex
private final java.lang.String regex
The regular expression for matching and obtaining capturing group values.
-
regexPattern
private final java.util.regex.Pattern regexPattern
The compiled regular expression ofregex.
-
groupIndexes
private final int[] groupIndexes
The array of group indexes to capturing groups.
-
EMPTY_STRING_MATCH_RESULT
private static final PatternWithGroups.EmptyStringMatchResult EMPTY_STRING_MATCH_RESULT
-
-
Constructor Detail
-
PatternWithGroups
protected PatternWithGroups()
Construct an empty pattern.
-
PatternWithGroups
public PatternWithGroups(java.lang.String regex) throws java.util.regex.PatternSyntaxExceptionConstruct a new pattern.- Parameters:
regex- the regular expression. If the expression isnullor an empty string then the pattern will only match anullor empty string.- Throws:
java.util.regex.PatternSyntaxException- if the regular expression could not be compiled.
-
PatternWithGroups
public PatternWithGroups(java.lang.String regex, int[] groupIndexes) throws java.util.regex.PatternSyntaxExceptionConstruct a new pattern.- Parameters:
regex- the regular expression. If the expression isnullor an empty string then the pattern will only match anullor empty string.groupIndexes- the array of group indexes to capturing groups.- Throws:
java.util.regex.PatternSyntaxException- if the regular expression could not be compiled.
-
PatternWithGroups
public PatternWithGroups(java.util.regex.Pattern regexPattern) throws java.lang.IllegalArgumentExceptionConstruct a new pattern.- Parameters:
regexPattern- the regular expression pattern.- Throws:
java.lang.IllegalArgumentException- if the regexPattern isnull.
-
PatternWithGroups
public PatternWithGroups(java.util.regex.Pattern regexPattern, int[] groupIndexes) throws java.lang.IllegalArgumentExceptionConstruct a new pattern.- Parameters:
regexPattern- the regular expression pattern.groupIndexes- the array of group indexes to capturing groups.- Throws:
java.lang.IllegalArgumentException- if the regexPattern isnull.
-
-
Method Detail
-
compile
private static java.util.regex.Pattern compile(java.lang.String regex) throws java.util.regex.PatternSyntaxException- Throws:
java.util.regex.PatternSyntaxException
-
getRegex
public final java.lang.String 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
public final java.util.regex.MatchResult match(java.lang.CharSequence cs)
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(java.lang.CharSequence cs, java.util.List<java.lang.String> groupValues) throws java.lang.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.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:
trueif the char sequence matches the pattern, otherwisefalse.- Throws:
java.lang.IllegalArgumentException- if the group values isnull.
-
match
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.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:
trueif the matches the pattern, otherwisefalse.- Throws:
java.lang.IllegalArgumentException- if group values isnull.
-
hashCode
public final int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public final boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
toString
public final java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-