Interface ZPath

All Superinterfaces:
Resolvable
All Known Implementing Classes:
ZPathImpl

public interface ZPath extends Resolvable
Abstracts a ZooKeeper ZNode path
  • Field Details

    • root

      static final ZPath root
      The root path: "/"
  • Method Details

    • parameter

      static String parameter()
      Returns the special node name that can be used for replacements at runtime via resolved(Object...) when passed via the various from() methods
    • parameter

      static String parameter(String name)
      Same as parameter() but allows you to specify an alternate code/name. This name has no effect and is only for debugging purposes. When toString() is called on ZPaths, this code shows.
    • parse

      static ZPath parse(String fullPath)
      Take a string path and return a ZPath.

      Note: This method always produces a fully resolved path despite the presence of any parameter-like elements (i.e, {one}). For substituting parameter elements and for proper parameter resolution status checks, use parseWithIds() instead.

      Parameters:
      fullPath - the path to parse
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if the path is invalid
    • parseWithIds

      static ZPath parseWithIds(String fullPath)
      Take a string path and return a ZPath. Each part of the path that is {XXXX} is replaced with parameter(). E.g. parseWithIds("/one/two/{first}/three/{second}") is the equivalent of calling ZPath.from("one", "two", parameter(), "three", parameter())
      Parameters:
      fullPath - the path to parse
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if the path is invalid
    • isId

      static boolean isId(String s)
      Return true if the given string conforms to the "{XXXX}" ID pattern
      Parameters:
      s - string to check
      Returns:
      true/false
    • parse

      static ZPath parse(String fullPath, UnaryOperator<String> nameFilter)
      Take a ZNode string path and return a ZPath
      Parameters:
      fullPath - the path to parse
      nameFilter - each part of the path is passed through this filter
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if the path is invalid
    • from

      static ZPath from(String... names)
      Convert individual path names into a ZPath. E.g. ZPath.from("my", "full", "path"). Any/all of the names can be passed as parameter() so that the path can be resolved later using of the resolved() methods.
      Parameters:
      names - path names
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if any of the names is invalid
    • from

      static ZPath from(List<String> names)
      Convert individual path names into a ZPath. Any/all of the names can be passed as parameter() so that the path can be resolved later using of the resolved() methods.
      Parameters:
      names - path names
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if any of the names is invalid
    • from

      static ZPath from(ZPath base, String... names)
      Convert individual path names into a ZPath starting at the given base. E.g. if base is "/home/base" ZPath.from(base, "my", "full", "path") would be "/home/base/my/full/path". Any/all of the names can be passed as parameter() so that the path can be resolved later using of the resolved() methods.
      Parameters:
      base - base/starting path
      names - path names
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if any of the names is invalid
    • from

      static ZPath from(ZPath base, List<String> names)
      Convert individual path names into a ZPath starting at the given base. Any/all of the names can be passed as parameter() so that the path can be resolved later using of the resolved() methods.
      Parameters:
      base - base/starting path
      names - path names
      Returns:
      ZPath
      Throws:
      IllegalArgumentException - if any of the names is invalid
    • resolved

      default ZPath resolved(Object... parameters)

      When creating paths, any node in the path can be set to parameter(). At runtime, the ZPath can be "resolved" by replacing these nodes with values.

      The replacement is the toString() value of the parameter object or, if the object implements NodeName, the value of nodeName().

      Specified by:
      resolved in interface Resolvable
      Parameters:
      parameters - list of replacements. Must have be the same length as the number of parameter nodes in the path
      Returns:
      new resolved ZPath
    • resolved

      ZPath resolved(List<Object> parameters)

      When creating paths, any node in the path can be set to parameter(). At runtime, the ZPath can be "resolved" by replacing these nodes with values.

      The replacement is the toString() value of the parameter object or, if the object implements NodeName, the value of nodeName().

      Specified by:
      resolved in interface Resolvable
      Parameters:
      parameters - list of replacements. Must have be the same length as the number of parameter nodes in the path
      Returns:
      new resolved ZPath
    • child

      ZPath child(Object child)

      Return a ZPath that represents a child ZNode of this ZPath. e.g. ZPath.from("a", "b").at("c") represents the path "/a/b/c"

      The replacement is the toString() value of child or, if it implements NodeName, the value of nodeName().

      Parameters:
      child - child node name
      Returns:
      ZPath
    • parent

      ZPath parent()
      Return this ZPath's parent
      Returns:
      parent ZPath
      Throws:
      NoSuchElementException - if this is the root ZPath
    • isRoot

      boolean isRoot()
      Return true/false if this is the root ZPath
      Returns:
      true false
    • isResolved

      boolean isResolved()
      Return true if this path is fully resolved (i.e. has no unresolved parameters).

      Note: ZPath's returned by the parse() method are always considered fully resolved, despite if there are remaining elements in the path which appear to be parameters (but are not, i.e. {one}).

      When working with parameters, use the parseWithIds() method, which returns a ZPath with a resolved state based on the presence of unresolved parameter elements in the ZPath.

      Returns:
      true/false
    • startsWith

      boolean startsWith(ZPath path)
      Return true if this path starts with the given path. i.e. ZPath.from("/one/two/three").startsWith(ZPath.from("/one/two")) returns true
      Parameters:
      path - base path
      Returns:
      true/false
    • fullPath

      String fullPath()
      The string full path that this ZPath represents
      Returns:
      full path
    • nodeName

      String nodeName()
      The node name at this ZPath
      Returns:
      name
    • toSchemaPathPattern

      Pattern toSchemaPathPattern()
      Return a regex Pattern useful for using in Schema
      Returns:
      pattern for this path