Class Path

java.lang.Object
com.yahoo.restapi.Path

public class Path extends Object
A normalized path which is able to match strings containing bracketed placeholders and return the values given at the placeholders. The path is split on '/', and each part is then URL decoded. E.g a path /a/1/bar/fuz/baz/%62%2f will match /a/{foo}/bar/{b}/baz/{c} and return foo=1, b=fuz, and c=c/ Only full path elements may be placeholders, i.e /a{bar} is not interpreted as one. If the path spec ends with /{*}, it will match urls with any rest path. The rest path (not including the trailing slash) will be available as getRest(). Note that for convenience in common use this has state which changes as a side effect of each matches(String) invocation. It is therefore for single thread use.
Author:
bratseth
  • Constructor Summary

    Constructors
    Constructor
    Description
    Path(URI uri)
    Creates a new Path for matching the given URI against patterns, which uses HttpURL.requirePathSegment(java.lang.String) as a segment validator.
    Path(URI uri, Consumer<String> validator)
    Creates a new Path for matching the given URI against patterns, with the given path segment validator.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(String placeholder)
    Returns the value of the given template variable in the last path matched, or null if the previous matches call returned false or if this has not matched anything yet.
    ai.vespa.http.HttpURL.Path
    The path this holds.
    ai.vespa.http.HttpURL.Path
    Returns the rest of the last matched path, or null if the path spec didn't end with {*}.
    boolean
    matches(String pathSpec)
    Parses the path according to pathSpec - must be called prior to get(java.lang.String) Returns whether this path matches the given template string.
     
    static Path
    Create a new Path for matching the given URI against patterns, without any segment validation.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Path

      public Path(URI uri)
      Creates a new Path for matching the given URI against patterns, which uses HttpURL.requirePathSegment(java.lang.String) as a segment validator.
    • Path

      public Path(URI uri, Consumer<String> validator)
      Creates a new Path for matching the given URI against patterns, with the given path segment validator.
  • Method Details

    • withoutValidation

      public static Path withoutValidation(URI uri)
      Create a new Path for matching the given URI against patterns, without any segment validation.
    • matches

      public boolean matches(String pathSpec)
      Parses the path according to pathSpec - must be called prior to get(java.lang.String) Returns whether this path matches the given template string. If the given template has placeholders, their values (accessible by get) are reset by calling this, whether the path matches the given template. This will NOT match empty path elements.
      Parameters:
      pathSpec - the literal path string to match to this
      Returns:
      true if the string matches, false otherwise
    • get

      public String get(String placeholder)
      Returns the value of the given template variable in the last path matched, or null if the previous matches call returned false or if this has not matched anything yet.
    • getRest

      public ai.vespa.http.HttpURL.Path getRest()
      Returns the rest of the last matched path, or null if the path spec didn't end with {*}.
    • getPath

      public ai.vespa.http.HttpURL.Path getPath()
      The path this holds.
    • toString

      public String toString()
      Overrides:
      toString in class Object