Class 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
    • Field Detail

      • templateString

        protected final java.lang.String templateString
    • 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 string
        parserArguments - The parsed arguments
      • UriTemplate

        protected UriTemplate​(java.lang.String templateString,
                              java.util.List<UriTemplate.PathSegment> segments)
        Parameters:
        templateString - The template
        segments - 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 class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

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

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

        public static UriTemplate of​(java.lang.String uri)
        Create a new UriTemplate 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 slash
        parserArguments - 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 template
        newSegments - 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 URI
        nested - 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 template
        len - The lenght
        parserArguments - 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 template
        parserArguments - 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