Interface Path

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Interface Description
      static interface  Path.Segments  
    • Method Detail

      • root

        static Path root()
        Get the zero-length path.
        Returns:
        the shared root path; never null
      • optionalRoot

        static Optional<Path> optionalRoot()
        Get an Optional reference to the root path. The resulting Optional will always be present.
        Returns:
        the shared optional root path; never null
      • parse

        static Path parse​(String path)
        Parse a JSON Path expression. Segments are separated by a single forward slash ('/'); any '~' or '/ ' literals must be escaped. Trailing slashes are ignored.
        Parameters:
        path - the path as a string; may not be null, but may be an empty string or "/" for a root path
        Returns:
        the path object; never null
      • parse

        static Path parse​(String path,
                          boolean resolveJsonPointerEscapes)
        Parse a JSON Path expression. Segments are separated by a single forward slash ('/'); any '~' or '/ ' literals must be escaped. Trailing slashes are ignored.
        Parameters:
        path - the path as a string; may not be null, but may be an empty string or "/" for a root path
        resolveJsonPointerEscapes - true if '~' and '/ ' literals are to be escaped as '~0' and '~1', respectively, or false if they are not to be escaped
        Returns:
        the path object; never null
      • isRoot

        default boolean isRoot()
        Return whether this path is the root path with no segments. This method is equivalent to size() == 0.
        Returns:
        true if this path contains exactly one segment, or false otherwise
      • isSingle

        default boolean isSingle()
        Return whether this path has a single segment. This method is equivalent to size() == 1.
        Returns:
        true if this path contains exactly one segment, or false otherwise
      • isMultiple

        default boolean isMultiple()
        Return whether this path has more than one segment. This method is equivalent to size() > 1.
        Returns:
        true if this path contains exactly one segment, or false otherwise
      • size

        int size()
        Get the number of segments in the path.
        Returns:
        the size of the path; never negative
      • parent

        Optional<Path> parent()
        Get the optional parent path.
        Returns:
        an optional containing the parent (if this is not the root path), or an empty optional if this is the root path.
      • lastSegment

        Optional<String> lastSegment()
        Get the last segment, if there is one.
        Returns:
        an optional containing the last segment of this path (if this is not the root path), or an empty optional if this is the root path.
      • subpath

        Path subpath​(int length)
        Get a portion of this path that has a specified number of segments.
        Parameters:
        length - the number of segments
        Returns:
        the subpath, or this path if the supplied length is equal to this.size()
      • segment

        String segment​(int index)
        Get the segment at the given index.
        Parameters:
        index - the index of the segment
        Returns:
        the segment
        Throws:
        IllegalArgumentException - if the index value is equal to or greater than #size()
      • append

        default Path append​(String relPath)
        Create a new path consisting of this path with one or more additional segments given by the relative path.
        Parameters:
        relPath - the relative path to be appended to this path; may not be null
        Returns:
        the new path
      • append

        Path append​(Path relPath)
        Create a new path consisting of this path appended with the given path that will be treated as a relative path.
        Parameters:
        relPath - the relative path to be appended to this path; may not be null
        Returns:
        the new path
      • toRelativePath

        String toRelativePath()
        Obtain the representation of this path as a relative path without the leading '/'.
        Returns:
        the relative path; never null but may be empty
      • fromRoot

        default void fromRoot​(Consumer<Path> consumer)
        Call the consumer with the path of every ancestor (except root) down to this path.
        Parameters:
        consumer - the function to call on each path segment