Interface ZPath

  • All Superinterfaces:
    Resolvable
    All Known Implementing Classes:
    ZPathImpl

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

      Fields 
      Modifier and Type Field Description
      static ZPath root
      The root path: "/"
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      ZPath child​(java.lang.Object child)
      Return a ZPath that represents a child ZNode of this ZPath.
      static ZPath from​(java.lang.String... names)
      Convert individual path names into a ZPath.
      static ZPath from​(java.util.List<java.lang.String> names)
      Convert individual path names into a ZPath.
      static ZPath from​(ZPath base, java.lang.String... names)
      Convert individual path names into a ZPath starting at the given base.
      static ZPath from​(ZPath base, java.util.List<java.lang.String> names)
      Convert individual path names into a ZPath starting at the given base.
      java.lang.String fullPath()
      The string full path that this ZPath represents
      static boolean isId​(java.lang.String s)
      Return true if the given string conforms to the "{XXXX}" ID pattern
      boolean isResolved()
      Return true if this path is fully resolved (i.e.
      boolean isRoot()
      Return true/false if this is the root ZPath
      java.lang.String nodeName()
      The node name at this ZPath
      static java.lang.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
      static java.lang.String parameter​(java.lang.String name)
      Same as parameter() but allows you to specify an alternate code/name.
      ZPath parent()
      Return this ZPath's parent
      static ZPath parse​(java.lang.String fullPath)
      Take a string path and return a ZPath
      static ZPath parse​(java.lang.String fullPath, java.util.function.UnaryOperator<java.lang.String> nameFilter)
      Take a ZNode string path and return a ZPath
      static ZPath parseWithIds​(java.lang.String fullPath)
      Take a string path and return a ZPath.
      default ZPath resolved​(java.lang.Object... parameters)
      When creating paths, any node in the path can be set to parameter().
      ZPath resolved​(java.util.List<java.lang.Object> parameters)
      When creating paths, any node in the path can be set to parameter().
      boolean startsWith​(ZPath path)
      Return true if this path starts with the given path.
      java.util.regex.Pattern toSchemaPathPattern()
      Return a regex Pattern useful for using in Schema
    • Field Detail

      • root

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

      • parameter

        static java.lang.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 java.lang.String parameter​(java.lang.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​(java.lang.String fullPath)
        Take a string path and return a ZPath
        Parameters:
        fullPath - the path to parse
        Returns:
        ZPath
        Throws:
        java.lang.IllegalArgumentException - if the path is invalid
      • parseWithIds

        static ZPath parseWithIds​(java.lang.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:
        java.lang.IllegalArgumentException - if the path is invalid
      • isId

        static boolean isId​(java.lang.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​(java.lang.String fullPath,
                           java.util.function.UnaryOperator<java.lang.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:
        java.lang.IllegalArgumentException - if the path is invalid
      • from

        static ZPath from​(java.lang.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:
        java.lang.IllegalArgumentException - if any of the names is invalid
      • from

        static ZPath from​(java.util.List<java.lang.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:
        java.lang.IllegalArgumentException - if any of the names is invalid
      • from

        static ZPath from​(ZPath base,
                          java.lang.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:
        java.lang.IllegalArgumentException - if any of the names is invalid
      • from

        static ZPath from​(ZPath base,
                          java.util.List<java.lang.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:
        java.lang.IllegalArgumentException - if any of the names is invalid
      • resolved

        default ZPath resolved​(java.lang.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​(java.util.List<java.lang.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​(java.lang.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:
        java.util.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 unresoled parameters)
        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

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

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

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