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 interfaceUriTemplate.PathSegmentRepresents an expandable path segment.protected static classUriTemplate.UriTemplateParserAn URI template parser.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.StringtemplateString
-
Constructor Summary
Constructors Modifier Constructor Description UriTemplate(java.lang.CharSequence templateString)Construct a new URI template for the given template.protectedUriTemplate(java.lang.CharSequence templateString, java.lang.Object... parserArguments)Construct a new URI template for the given template.protectedUriTemplate(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)intcompareTo(UriTemplate o)protected UriTemplate.UriTemplateParsercreateParser(java.lang.String templateString, java.lang.Object... parserArguments)Creates a parser.booleanequals(java.lang.Object o)java.lang.Stringexpand(java.lang.Object bean)Expand the string with the given bean.java.lang.Stringexpand(java.util.Map<java.lang.String,java.lang.Object> parameters)Expand the string with the given parameters.longgetPathVariableSegmentCount()longgetRawSegmentCount()intgetRawSegmentLength()longgetVariableSegmentCount()inthashCode()UriTemplatenest(java.lang.CharSequence uriTemplate)Nests another URI template with this template.protected UriTemplatenest(java.lang.CharSequence uriTemplate, java.lang.Object... parserArguments)Nests another URI template with this template.protected UriTemplatenewUriTemplate(java.lang.CharSequence uriTemplate, java.util.List<UriTemplate.PathSegment> newSegments)protected java.lang.StringnormalizeNested(java.lang.String uri, java.lang.CharSequence nested)Normalize a nested URI.static UriTemplateof(java.lang.String uri)Create a newUriTemplatefor the given URI.java.lang.StringtoString()protected java.lang.StringtoString(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:
toStringin classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
compareTo
public int compareTo(UriTemplate o)
- Specified by:
compareToin interfacejava.lang.Comparable<UriTemplate>
-
of
public static UriTemplate of(java.lang.String uri)
Create a newUriTemplatefor 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
-
-