public class UriTemplate extends Object implements 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.
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 and Type | Field and Description |
---|---|
protected String |
templateString |
Modifier | Constructor and Description |
---|---|
|
UriTemplate(CharSequence templateString)
Construct a new URI template for the given template.
|
protected |
UriTemplate(CharSequence templateString,
Object... parserArguments)
Construct a new URI template for the given template.
|
protected |
UriTemplate(String templateString,
List<UriTemplate.PathSegment> segments) |
Modifier and Type | Method and Description |
---|---|
protected List<UriTemplate.PathSegment> |
buildNestedSegments(CharSequence uriTemplate,
int len,
Object... parserArguments) |
int |
compareTo(UriTemplate o) |
protected UriTemplate.UriTemplateParser |
createParser(String templateString,
Object... parserArguments)
Creates a parser.
|
boolean |
equals(Object o) |
String |
expand(Map<String,Object> parameters)
Expand the string with the given parameters.
|
String |
expand(Object bean)
Expand the string with the given bean.
|
long |
getPathVariableSegmentCount() |
long |
getRawSegmentCount() |
int |
getRawSegmentLength() |
long |
getVariableSegmentCount() |
int |
hashCode() |
UriTemplate |
nest(CharSequence uriTemplate)
Nests another URI template with this template.
|
protected UriTemplate |
nest(CharSequence uriTemplate,
Object... parserArguments)
Nests another URI template with this template.
|
protected UriTemplate |
newUriTemplate(CharSequence uriTemplate,
List<UriTemplate.PathSegment> newSegments) |
protected String |
normalizeNested(String uri,
CharSequence nested)
Normalize a nested URI.
|
static UriTemplate |
of(String uri)
Create a new
UriTemplate for the given URI. |
String |
toString() |
protected String |
toString(Predicate<UriTemplate.PathSegment> filter)
Returns the template as a string filtering the segments
with the provided filter.
|
protected final String templateString
public UriTemplate(CharSequence templateString)
templateString
- The template stringprotected UriTemplate(CharSequence templateString, Object... parserArguments)
templateString
- The template stringparserArguments
- The parsed argumentsprotected UriTemplate(String templateString, 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(CharSequence uriTemplate)
uriTemplate
- The URI template. If it does not begin with forward slash it will automatically be appended with forward slashpublic String expand(Map<String,Object> parameters)
parameters
- The parameterspublic String expand(Object bean)
bean
- The beanpublic int compareTo(UriTemplate o)
compareTo
in interface Comparable<UriTemplate>
public static UriTemplate of(String uri)
UriTemplate
for the given URI.uri
- The URIprotected UriTemplate nest(CharSequence uriTemplate, 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(CharSequence uriTemplate, List<UriTemplate.PathSegment> newSegments)
uriTemplate
- The URI templatenewSegments
- The new segmentsUriTemplate
protected String normalizeNested(String uri, CharSequence nested)
uri
- The URInested
- The nested URIprotected List<UriTemplate.PathSegment> buildNestedSegments(CharSequence uriTemplate, int len, Object... parserArguments)
uriTemplate
- The URI templatelen
- The lenghtparserArguments
- The parsed argumentsprotected UriTemplate.UriTemplateParser createParser(String templateString, Object... parserArguments)
templateString
- The templateparserArguments
- The parsed argumentsprotected String toString(Predicate<UriTemplate.PathSegment> filter)
filter
- The filter to test segments