Package io.micronaut.http.uri
Class UriTemplate
- java.lang.Object
-
- io.micronaut.http.uri.UriTemplate
-
- All Implemented Interfaces:
java.lang.Comparable<UriTemplate>
- Direct Known Subclasses:
UriMatchTemplate
public class UriTemplate extends java.lang.Object implements java.lang.Comparable<UriTemplate>
A Fast Implementation of URI Template specification. See rfc6570 and URI.js.
Note: this class has a natural ordering that is inconsistent with equals.
- Since:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
UriTemplate.PathSegment
Represents an expandable path segment.protected static class
UriTemplate.UriTemplateParser
An URI template parser.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
templateString
-
Constructor Summary
Constructors Modifier Constructor Description UriTemplate(java.lang.CharSequence templateString)
Construct a new URI template for the given template.protected
UriTemplate(java.lang.CharSequence templateString, java.lang.Object... parserArguments)
Construct a new URI template for the given template.protected
UriTemplate(java.lang.String templateString, java.util.List<UriTemplate.PathSegment> segments)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<UriTemplate.PathSegment>
buildNestedSegments(java.lang.CharSequence uriTemplate, int len, java.lang.Object... parserArguments)
int
compareTo(UriTemplate o)
protected UriTemplate.UriTemplateParser
createParser(java.lang.String templateString, java.lang.Object... parserArguments)
Creates a parser.boolean
equals(java.lang.Object o)
java.lang.String
expand(java.lang.Object bean)
Expand the string with the given bean.java.lang.String
expand(java.util.Map<java.lang.String,java.lang.Object> parameters)
Expand the string with the given parameters.long
getPathVariableSegmentCount()
long
getRawSegmentCount()
int
getRawSegmentLength()
long
getVariableSegmentCount()
int
hashCode()
UriTemplate
nest(java.lang.CharSequence uriTemplate)
Nests another URI template with this template.protected UriTemplate
nest(java.lang.CharSequence uriTemplate, java.lang.Object... parserArguments)
Nests another URI template with this template.protected UriTemplate
newUriTemplate(java.lang.CharSequence uriTemplate, java.util.List<UriTemplate.PathSegment> newSegments)
protected java.lang.String
normalizeNested(java.lang.String uri, java.lang.CharSequence nested)
Normalize a nested URI.static UriTemplate
of(java.lang.String uri)
Create a newUriTemplate
for the given URI.java.lang.String
toString()
protected java.lang.String
toString(java.util.function.Predicate<UriTemplate.PathSegment> filter)
Returns the template as a string filtering the segments with the provided filter.
-
-
-
Constructor Detail
-
UriTemplate
public UriTemplate(java.lang.CharSequence templateString)
Construct a new URI template for the given template.- Parameters:
templateString
- The template string
-
UriTemplate
protected UriTemplate(java.lang.CharSequence templateString, java.lang.Object... parserArguments)
Construct a new URI template for the given template.- Parameters:
templateString
- The template stringparserArguments
- The parsed arguments
-
UriTemplate
protected UriTemplate(java.lang.String templateString, java.util.List<UriTemplate.PathSegment> segments)
- Parameters:
templateString
- The templatesegments
- The list of segments
-
-
Method Detail
-
getVariableSegmentCount
public long getVariableSegmentCount()
- Returns:
- The number of segments that are variable
-
getPathVariableSegmentCount
public long getPathVariableSegmentCount()
- Returns:
- The number of path segments that are variable
-
getRawSegmentCount
public long getRawSegmentCount()
- Returns:
- The number of segments that are raw
-
getRawSegmentLength
public int getRawSegmentLength()
- Returns:
- The number of segments that are raw
-
nest
public UriTemplate nest(java.lang.CharSequence uriTemplate)
Nests another URI template with this template.- Parameters:
uriTemplate
- The URI template. If it does not begin with forward slash it will automatically be appended with forward slash- Returns:
- The new URI template
-
expand
public java.lang.String expand(java.util.Map<java.lang.String,java.lang.Object> parameters)
Expand the string with the given parameters.- Parameters:
parameters
- The parameters- Returns:
- The expanded URI
-
expand
public java.lang.String expand(java.lang.Object bean)
Expand the string with the given bean.- Parameters:
bean
- The bean- Returns:
- The expanded URI
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
compareTo
public int compareTo(UriTemplate o)
- Specified by:
compareTo
in interfacejava.lang.Comparable<UriTemplate>
-
of
public static UriTemplate of(java.lang.String uri)
Create a newUriTemplate
for the given URI.- Parameters:
uri
- The URI- Returns:
- The template
-
nest
protected UriTemplate nest(java.lang.CharSequence uriTemplate, java.lang.Object... parserArguments)
Nests another URI template with this template.- Parameters:
uriTemplate
- The URI template. If it does not begin with forward slash it will automatically be appended with forward slashparserArguments
- The parsed arguments- Returns:
- The new URI template
-
newUriTemplate
protected UriTemplate newUriTemplate(java.lang.CharSequence uriTemplate, java.util.List<UriTemplate.PathSegment> newSegments)
- Parameters:
uriTemplate
- The URI templatenewSegments
- The new segments- Returns:
- The new
UriTemplate
-
normalizeNested
protected java.lang.String normalizeNested(java.lang.String uri, java.lang.CharSequence nested)
Normalize a nested URI.- Parameters:
uri
- The URInested
- The nested URI- Returns:
- The new URI
-
buildNestedSegments
protected java.util.List<UriTemplate.PathSegment> buildNestedSegments(java.lang.CharSequence uriTemplate, int len, java.lang.Object... parserArguments)
- Parameters:
uriTemplate
- The URI templatelen
- The lenghtparserArguments
- The parsed arguments- Returns:
- A list of path segments
-
createParser
protected UriTemplate.UriTemplateParser createParser(java.lang.String templateString, java.lang.Object... parserArguments)
Creates a parser.- Parameters:
templateString
- The templateparserArguments
- The parsed arguments- Returns:
- The created parser
-
toString
protected java.lang.String toString(java.util.function.Predicate<UriTemplate.PathSegment> filter)
Returns the template as a string filtering the segments with the provided filter.- Parameters:
filter
- The filter to test segments- Returns:
- The template as a string
-
-