Top Description Inners Fields Constructors Methods
org.glassfish.tyrus.core.uri.internal

public Class PatternWithGroups

extends Object
Class Inheritance
Known Direct Subclasses
org.glassfish.tyrus.core.uri.internal.PathPattern
Imports
java.util.List, .Map, java.util.regex.MatchResult, .Matcher, .Pattern, .PatternSyntaxException

A pattern for matching a string against a regular expression and returning capturing group values for any capturing groups present in the expression.
Authors
Paul Sandoz, Gerard Davison (gerard.davison at oracle.com)

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private class

Field Summary

Modifier and TypeField and Description
public static final PatternWithGroups
EMPTY

The empty pattern that matches the null or empty string.

private static final int[]
private static final PatternWithGroups.EmptyStringMatchResult
private final int[]
groupIndexes

The array of group indexes to capturing groups.

private final String
regex

The regular expression for matching and obtaining capturing group values.

private final Pattern
regexPattern

The compiled regular expression of regex.

Constructor Summary

AccessConstructor and Description
protected
PatternWithGroups()

Construct an empty pattern.

public
PatternWithGroups(final String
the regular expression. If the expression is null or an empty string then the pattern will only match a null or empty string.
regex
)

Construct a new pattern.

public
PatternWithGroups(final String
the regular expression. If the expression is null or an empty string then the pattern will only match a null or empty string.
regex
,
final int[]
the array of group indexes to capturing groups.
groupIndexes
)

Construct a new pattern.

public
PatternWithGroups(final Pattern
the regular expression pattern.
regexPattern
)

Construct a new pattern.

public
PatternWithGroups(final Pattern
the regular expression pattern.
regexPattern
,
final int[]
the array of group indexes to capturing groups.
groupIndexes
)

Construct a new pattern.

Method Summary

Modifier and TypeMethod and Description
private static Pattern
compile(final String regex)

public final boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public final int[]

Returns:

the group indexes to capturing groups.
getGroupIndexes
()

Get the group indexes to capturing groups.

public final String

Returns:

the regular expression.
getRegex
()

Get the regular expression.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

public final MatchResult

Returns:

the match result, otherwise null if no match occurs.
match
(final CharSequence
the char sequence to match against the template.
cs
)

Match against the pattern.

public final boolean

Returns:

true if the char sequence matches the pattern, otherwise false.
match
(final CharSequence
the char sequence to match against the template.
cs
,
final List<String>
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.
groupValues
)

Match against the pattern.

public final boolean

Returns:

true if the matches the pattern, otherwise false.
match
(final CharSequence
the char sequence to match against the template.
cs
,
final List<String>
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.
groupNames
,
final Map<String, String>
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.
groupValues
)

Match against the pattern.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

EMPTYback to summary
public static final PatternWithGroups EMPTY

The empty pattern that matches the null or empty string.

EMPTY_INT_ARRAYback to summary
private static final int[] EMPTY_INT_ARRAY
EMPTY_STRING_MATCH_RESULTback to summary
private static final PatternWithGroups.EmptyStringMatchResult EMPTY_STRING_MATCH_RESULT
groupIndexesback to summary
private final int[] groupIndexes

The array of group indexes to capturing groups.

regexback to summary
private final String regex

The regular expression for matching and obtaining capturing group values.

regexPatternback to summary
private final Pattern regexPattern

The compiled regular expression of regex.

Constructor Detail

PatternWithGroupsback to summary
protected PatternWithGroups()

Construct an empty pattern.

PatternWithGroupsback to summary
public PatternWithGroups(final String regex) throws PatternSyntaxException

Construct a new pattern.

Parameters
regex:String

the regular expression. If the expression is null or an empty string then the pattern will only match a null or empty string.

Exceptions
PatternSyntaxException:
if the regular expression could not be compiled.
PatternWithGroupsback to summary
public PatternWithGroups(final String regex, final int[] groupIndexes) throws PatternSyntaxException

Construct a new pattern.

Parameters
regex:String

the regular expression. If the expression is null or an empty string then the pattern will only match a null or empty string.

groupIndexes:int[]

the array of group indexes to capturing groups.

Exceptions
PatternSyntaxException:
if the regular expression could not be compiled.
PatternWithGroupsback to summary
public PatternWithGroups(final Pattern regexPattern) throws IllegalArgumentException

Construct a new pattern.

Parameters
regexPattern:Pattern

the regular expression pattern.

Exceptions
IllegalArgumentException:
if the regexPattern is null.
PatternWithGroupsback to summary
public PatternWithGroups(final Pattern regexPattern, final int[] groupIndexes) throws IllegalArgumentException

Construct a new pattern.

Parameters
regexPattern:Pattern

the regular expression pattern.

groupIndexes:int[]

the array of group indexes to capturing groups.

Exceptions
IllegalArgumentException:
if the regexPattern is null.

Method Detail

compileback to summary
private static Pattern compile(final String regex) throws PatternSyntaxException
equalsback to summary
public final boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getGroupIndexesback to summary
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:int[]

the group indexes to capturing groups.

getRegexback to summary
public final String getRegex()

Get the regular expression.

Returns:String

the regular expression.

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
matchback to summary
public final MatchResult match(final CharSequence cs)

Match against the pattern.

Parameters
cs:CharSequence

the char sequence to match against the template.

Returns:MatchResult

the match result, otherwise null if no match occurs.

matchback to summary
public final boolean match(final CharSequence cs, final 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:CharSequence

the char sequence to match against the template.

groupValues:List<String>

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:boolean

true if the char sequence matches the pattern, otherwise false.

Exceptions
IllegalArgumentException:
if the group values is null.
matchback to summary
public final boolean match(final CharSequence cs, final List<String> groupNames, final Map<String, 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:CharSequence

the char sequence to match against the template.

groupNames:List<String>

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:Map<String, String>

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:boolean

true if the matches the pattern, otherwise false.

Exceptions
IllegalArgumentException:
if group values is null.
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
org.glassfish.tyrus.core.uri.internal back to summary

private final Class PatternWithGroups.EmptyStringMatchResult

extends Object
implements MatchResult
Class Inheritance
  • java.lang.Object
  • org.glassfish.tyrus.core.uri.internal.PatternWithGroups.EmptyStringMatchResult
All Implemented Interfaces
java.util.regex.MatchResult

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public int
end()

Implements java.util.regex.MatchResult.end.

Returns the offset after the last character matched.

public int
end(final int
The index of a capturing group in this matcher's pattern
group
)

Implements java.util.regex.MatchResult.end.

Returns the offset after the last character of the subsequence captured by the given group during this match.

public String
group()

Implements java.util.regex.MatchResult.group.

Returns the input subsequence matched by the previous match.

public String
group(final int
The index of a capturing group in this matcher's pattern
group
)

Implements java.util.regex.MatchResult.group.

Returns the input subsequence captured by the given group during the previous match operation.

public int
groupCount()

Implements java.util.regex.MatchResult.groupCount.

Returns the number of capturing groups in this match result's pattern.

public int
start()

Implements java.util.regex.MatchResult.start.

Returns the start index of the match.

public int
start(final int
The index of a capturing group in this matcher's pattern
group
)

Implements java.util.regex.MatchResult.start.

Returns the start index of the subsequence captured by the given group during this match.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EmptyStringMatchResultback to summary
private EmptyStringMatchResult()

Method Detail

endback to summary
public int end()

Implements java.util.regex.MatchResult.end.

Doc from java.util.regex.MatchResult.end.

Returns the offset after the last character matched.

Returns:int

The offset after the last character matched

Annotations
@Override
endback to summary
public int end(final int group)

Implements java.util.regex.MatchResult.end.

Doc from java.util.regex.MatchResult.end.

Returns the offset after the last character of the subsequence captured by the given group during this match.

Capturing groups are indexed from left to right, starting at one. Group zero denotes the entire pattern, so the expression m.end(0) is equivalent to m.end().

Parameters
group:int

The index of a capturing group in this matcher's pattern

Returns:int

The offset after the last character captured by the group, or -1 if the match was successful but the group itself did not match anything

Annotations
@Override
groupback to summary
public String group()

Implements java.util.regex.MatchResult.group.

Doc from java.util.regex.MatchResult.group.

Returns the input subsequence matched by the previous match.

For a matcher m with input sequence s, the expressions m.group() and s.substring(m.start(), m.end()) are equivalent.

Note that some patterns, for example a*, match the empty string. This method will return the empty string when the pattern successfully matches the empty string in the input.

Returns:String

The (possibly empty) subsequence matched by the previous match, in string form

Annotations
@Override
groupback to summary
public String group(final int group)

Implements java.util.regex.MatchResult.group.

Doc from java.util.regex.MatchResult.group.

Returns the input subsequence captured by the given group during the previous match operation.

For a matcher m, input sequence s, and group index g, the expressions m.group(g) and s.substring(m.start(g), m.end(g)) are equivalent.

Capturing groups are indexed from left to right, starting at one. Group zero denotes the entire pattern, so the expression m.group(0) is equivalent to m.group().

If the match was successful but the group specified failed to match any part of the input sequence, then null is returned. Note that some groups, for example (a*), match the empty string. This method will return the empty string when such a group successfully matches the empty string in the input.

Parameters
group:int

The index of a capturing group in this matcher's pattern

Returns:String

The (possibly empty) subsequence captured by the group during the previous match, or null if the group failed to match part of the input

Annotations
@Override
groupCountback to summary
public int groupCount()

Implements java.util.regex.MatchResult.groupCount.

Doc from java.util.regex.MatchResult.groupCount.

Returns the number of capturing groups in this match result's pattern.

Group zero denotes the entire pattern by convention. It is not included in this count.

Any non-negative integer smaller than or equal to the value returned by this method is guaranteed to be a valid group index for this matcher.

Returns:int

The number of capturing groups in this matcher's pattern

Annotations
@Override
startback to summary
public int start()

Implements java.util.regex.MatchResult.start.

Doc from java.util.regex.MatchResult.start.

Returns the start index of the match.

Returns:int

The index of the first character matched

Annotations
@Override
startback to summary
public int start(final int group)

Implements java.util.regex.MatchResult.start.

Doc from java.util.regex.MatchResult.start.

Returns the start index of the subsequence captured by the given group during this match.

Capturing groups are indexed from left to right, starting at one. Group zero denotes the entire pattern, so the expression m.start(0) is equivalent to m.start().

Parameters
group:int

The index of a capturing group in this matcher's pattern

Returns:int

The index of the first character captured by the group, or -1 if the match was successful but the group itself did not match anything

Annotations
@Override
org.glassfish.tyrus.core.uri.internal back to summary

private final Class PatternWithGroups.GroupIndexMatchResult

extends Object
implements MatchResult
Class Inheritance
  • java.lang.Object
  • org.glassfish.tyrus.core.uri.internal.PatternWithGroups.GroupIndexMatchResult
All Implemented Interfaces
java.util.regex.MatchResult

Field Summary

Modifier and TypeField and Description
private final MatchResult

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
end()

Implements java.util.regex.MatchResult.end.

Returns the offset after the last character matched.

public int
end(final int
The index of a capturing group in this matcher's pattern
group
)

Implements java.util.regex.MatchResult.end.

Returns the offset after the last character of the subsequence captured by the given group during this match.

public String
group()

Implements java.util.regex.MatchResult.group.

Returns the input subsequence matched by the previous match.

public String
group(final int
The index of a capturing group in this matcher's pattern
group
)

Implements java.util.regex.MatchResult.group.

Returns the input subsequence captured by the given group during the previous match operation.

public int
groupCount()

Implements java.util.regex.MatchResult.groupCount.

Returns the number of capturing groups in this match result's pattern.

public int
start()

Implements java.util.regex.MatchResult.start.

Returns the start index of the match.

public int
start(final int
The index of a capturing group in this matcher's pattern
group
)

Implements java.util.regex.MatchResult.start.

Returns the start index of the subsequence captured by the given group during this match.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

resultback to summary
private final MatchResult result

Constructor Detail

GroupIndexMatchResultback to summary
pack-priv GroupIndexMatchResult(final MatchResult r)

Method Detail

endback to summary
public int end()

Implements java.util.regex.MatchResult.end.

Doc from java.util.regex.MatchResult.end.

Returns the offset after the last character matched.

Returns:int

The offset after the last character matched

Annotations
@Override
endback to summary
public int end(final int group)

Implements java.util.regex.MatchResult.end.

Doc from java.util.regex.MatchResult.end.

Returns the offset after the last character of the subsequence captured by the given group during this match.

Capturing groups are indexed from left to right, starting at one. Group zero denotes the entire pattern, so the expression m.end(0) is equivalent to m.end().

Parameters
group:int

The index of a capturing group in this matcher's pattern

Returns:int

The offset after the last character captured by the group, or -1 if the match was successful but the group itself did not match anything

Annotations
@Override
groupback to summary
public String group()

Implements java.util.regex.MatchResult.group.

Doc from java.util.regex.MatchResult.group.

Returns the input subsequence matched by the previous match.

For a matcher m with input sequence s, the expressions m.group() and s.substring(m.start(), m.end()) are equivalent.

Note that some patterns, for example a*, match the empty string. This method will return the empty string when the pattern successfully matches the empty string in the input.

Returns:String

The (possibly empty) subsequence matched by the previous match, in string form

Annotations
@Override
groupback to summary
public String group(final int group)

Implements java.util.regex.MatchResult.group.

Doc from java.util.regex.MatchResult.group.

Returns the input subsequence captured by the given group during the previous match operation.

For a matcher m, input sequence s, and group index g, the expressions m.group(g) and s.substring(m.start(g), m.end(g)) are equivalent.

Capturing groups are indexed from left to right, starting at one. Group zero denotes the entire pattern, so the expression m.group(0) is equivalent to m.group().

If the match was successful but the group specified failed to match any part of the input sequence, then null is returned. Note that some groups, for example (a*), match the empty string. This method will return the empty string when such a group successfully matches the empty string in the input.

Parameters
group:int

The index of a capturing group in this matcher's pattern

Returns:String

The (possibly empty) subsequence captured by the group during the previous match, or null if the group failed to match part of the input

Annotations
@Override
groupCountback to summary
public int groupCount()

Implements java.util.regex.MatchResult.groupCount.

Doc from java.util.regex.MatchResult.groupCount.

Returns the number of capturing groups in this match result's pattern.

Group zero denotes the entire pattern by convention. It is not included in this count.

Any non-negative integer smaller than or equal to the value returned by this method is guaranteed to be a valid group index for this matcher.

Returns:int

The number of capturing groups in this matcher's pattern

Annotations
@Override
startback to summary
public int start()

Implements java.util.regex.MatchResult.start.

Doc from java.util.regex.MatchResult.start.

Returns the start index of the match.

Returns:int

The index of the first character matched

Annotations
@Override
startback to summary
public int start(final int group)

Implements java.util.regex.MatchResult.start.

Doc from java.util.regex.MatchResult.start.

Returns the start index of the subsequence captured by the given group during this match.

Capturing groups are indexed from left to right, starting at one. Group zero denotes the entire pattern, so the expression m.start(0) is equivalent to m.start().

Parameters
group:int

The index of a capturing group in this matcher's pattern

Returns:int

The index of the first character captured by the group, or -1 if the match was successful but the group itself did not match anything

Annotations
@Override