public class UriTemplate extends java.lang.Object implements java.lang.Comparable<UriTemplate>
A Fast Implementation of URI Template specification. See https://tools.ietf.org/html/rfc6570 and https://medialize.github.io/URI.js/uri-template.html.
Note: this class has a natural ordering that is inconsistent with equals.
Modifier and Type | Class and Description |
---|---|
protected static interface |
UriTemplate.PathSegment
Represents an expandable path segment.
|
protected static class |
UriTemplate.UriTemplateParser
An URI template parser.
|
Modifier | Constructor and 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) |
Modifier and Type | Method and 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.util.Map<java.lang.String,java.lang.Object> parameters)
Expand the string with the given parameters.
|
java.lang.String |
expand(java.lang.Object bean)
Expand the string with the given bean.
|
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 new
UriTemplate 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.
|
public UriTemplate(java.lang.CharSequence templateString)
templateString
- The template stringprotected UriTemplate(java.lang.CharSequence templateString, java.lang.Object... parserArguments)
templateString
- The template stringparserArguments
- The parsed argumentsprotected UriTemplate(java.lang.String templateString, java.util.List<UriTemplate.PathSegment> segments)
templateString
- The templatesegments
- The list of segmentspublic long getVariableSegmentCount()
public long getPathVariableSegmentCount()
public long getRawSegmentCount()
public int getRawSegmentLength()
public UriTemplate nest(java.lang.CharSequence uriTemplate)
uriTemplate
- The URI template. If it does not begin with forward slash it will automatically be appended with forward slashpublic java.lang.String expand(java.util.Map<java.lang.String,java.lang.Object> parameters)
parameters
- The parameterspublic java.lang.String expand(java.lang.Object bean)
bean
- The beanpublic java.lang.String toString()
toString
in class java.lang.Object
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public int compareTo(UriTemplate o)
compareTo
in interface java.lang.Comparable<UriTemplate>
public static UriTemplate of(java.lang.String uri)
UriTemplate
for the given URI.uri
- The URIprotected UriTemplate nest(java.lang.CharSequence uriTemplate, java.lang.Object... parserArguments)
uriTemplate
- The URI template. If it does not begin with forward slash it will automatically be
appended with forward slashparserArguments
- The parsed argumentsprotected UriTemplate newUriTemplate(java.lang.CharSequence uriTemplate, java.util.List<UriTemplate.PathSegment> newSegments)
uriTemplate
- The URI templatenewSegments
- The new segmentsUriTemplate
protected java.lang.String normalizeNested(java.lang.String uri, java.lang.CharSequence nested)
uri
- The URInested
- The nested URIprotected java.util.List<UriTemplate.PathSegment> buildNestedSegments(java.lang.CharSequence uriTemplate, int len, java.lang.Object... parserArguments)
uriTemplate
- The URI templatelen
- The lenghtparserArguments
- The parsed argumentsprotected UriTemplate.UriTemplateParser createParser(java.lang.String templateString, java.lang.Object... parserArguments)
templateString
- The templateparserArguments
- The parsed argumentsprotected java.lang.String toString(java.util.function.Predicate<UriTemplate.PathSegment> filter)
filter
- The filter to test segments