Class UriTemplate

java.lang.Object
io.micronaut.http.uri.UriTemplate
All Implemented Interfaces:
Comparable<UriTemplate>
Direct Known Subclasses:
UriMatchTemplate

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.

Since:
1.0
Author:
Graeme Rocher
  • Field Details

    • templateString

      protected final String templateString
  • Constructor Details

    • UriTemplate

      public UriTemplate(CharSequence templateString)
      Construct a new URI template for the given template.
      Parameters:
      templateString - The template string
    • UriTemplate

      protected UriTemplate(CharSequence templateString, Object... parserArguments)
      Construct a new URI template for the given template.
      Parameters:
      templateString - The template string
      parserArguments - The parsed arguments
    • UriTemplate

      protected UriTemplate(String templateString, List<UriTemplate.PathSegment> segments)
      Parameters:
      templateString - The template
      segments - The list of segments
  • Method Details

    • 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(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 String expand(Map<String,Object> parameters)
      Expand the string with the given parameters.
      Parameters:
      parameters - The parameters
      Returns:
      The expanded URI
    • expand

      public String expand(Object bean)
      Expand the string with the given bean.
      Parameters:
      bean - The bean
      Returns:
      The expanded URI
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(UriTemplate o)
      Specified by:
      compareTo in interface Comparable<UriTemplate>
    • of

      public static UriTemplate of(String uri)
      Create a new UriTemplate for the given URI.
      Parameters:
      uri - The URI
      Returns:
      The template
    • nest

      protected UriTemplate nest(CharSequence uriTemplate, 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 slash
      parserArguments - The parsed arguments
      Returns:
      The new URI template
    • newUriTemplate

      protected UriTemplate newUriTemplate(CharSequence uriTemplate, List<UriTemplate.PathSegment> newSegments)
      Parameters:
      uriTemplate - The URI template
      newSegments - The new segments
      Returns:
      The new UriTemplate
    • normalizeNested

      protected String normalizeNested(String uri, CharSequence nested)
      Normalize a nested URI.
      Parameters:
      uri - The URI
      nested - The nested URI
      Returns:
      The new URI
    • buildNestedSegments

      protected List<UriTemplate.PathSegment> buildNestedSegments(CharSequence uriTemplate, int len, Object... parserArguments)
      Parameters:
      uriTemplate - The URI template
      len - The lenght
      parserArguments - The parsed arguments
      Returns:
      A list of path segments
    • createParser

      protected UriTemplate.UriTemplateParser createParser(String templateString, Object... parserArguments)
      Creates a parser.
      Parameters:
      templateString - The template
      parserArguments - The parsed arguments
      Returns:
      The created parser
    • toString

      protected String toString(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