java.lang.Object
org.apache.jackrabbit.oak.plugins.document.Path
All Implemented Interfaces:
Comparable<Path>, CacheValue

public final class Path extends Object implements CacheValue, Comparable<Path>
The Path class is closely modeled after the semantics of PathUtils in oak-commons. Corresponding methods in this class can be used as a replacement for the methods in PathUtils on Path objects.
  • Field Details

    • ROOT

      public static final Path ROOT
  • Constructor Details

    • Path

      public Path(@NotNull @NotNull Path parent, @NotNull @NotNull String name)
      Creates a new Path from the given parent Path. The name of the new Path cannot be the empty String.
      Parameters:
      parent - the parent Path.
      name - the name of the new Path.
      Throws:
      IllegalArgumentException - if the name is empty.
    • Path

      public Path(@NotNull @NotNull String name)
      Creates a relative path with a single name element. The name cannot be the empty String.
      Parameters:
      name - the name of the first path element.
      Throws:
      IllegalArgumentException - if the name is empty.
  • Method Details

    • getName

      @NotNull public @NotNull String getName()
      Returns the name of this path. The ROOT is the only path with an empty name. That is a String with length zero.
      Returns:
      the name of this path.
    • elements

      @NotNull public @NotNull Iterable<String> elements()
      Returns the names of the path elements with increasing getDepth() starting at depth 1.
      Returns:
      the names of the path elements.
    • isRoot

      public boolean isRoot()
      Returns true if this is the ROOT path; false otherwise.
      Returns:
      whether this is the ROOT path.
    • getParent

      @Nullable public @Nullable Path getParent()
      The parent of this path or null if this path does not have a parent. The ROOT path and the first path element of a relative path do not have a parent.
      Returns:
      the parent of this path or null if this path does not have a parent.
    • length

      public int length()
      Returns:
      the number of characters of the String representation of this path.
    • getDepth

      public int getDepth()
      The depth of this path. The ROOT has a depth of 0. The path /foo/bar as well as bar/baz have depth 2.
      Returns:
      the depth of the path.
    • getAncestor

      @NotNull public @NotNull Path getAncestor(int nth)
      Get the nth ancestor of a path. The 1st ancestor is the parent path, 2nd ancestor the grandparent path, and so on...

      If nth <= 0, then this path is returned.

      Parameters:
      nth - indicates the ancestor level for which the path should be calculated.
      Returns:
      the ancestor path
    • isAncestorOf

      public boolean isAncestorOf(@NotNull @NotNull Path other)
      Return true if this path is an ancestor of the other path, otherwise false.
      Parameters:
      other - the other path.
      Returns:
      whether this path is an ancestor of the other path.
    • isAbsolute

      public boolean isAbsolute()
      Returns:
      true if this is an absolute path; false otherwise.
    • fromString

      @NotNull public static @NotNull Path fromString(@NotNull @NotNull String path) throws IllegalArgumentException
      Creates a Path from a String.
      Parameters:
      path - the String to parse.
      Returns:
      the Path from the String.
      Throws:
      IllegalArgumentException - if the path is the empty String.
    • toStringBuilder

      @NotNull public @NotNull StringBuilder toStringBuilder(@NotNull @NotNull StringBuilder sb)
      Appends the String representation of this Path to the passed StringBuilder. See also toString().
      Parameters:
      sb - the StringBuilder this Path is appended to.
      Returns:
      the passed StringBuilder.
    • getMemory

      public int getMemory()
      Description copied from interface: CacheValue
      The estimated amount of memory used by this object, in bytes.
      Specified by:
      getMemory in interface CacheValue
      Returns:
      the estimated number of bytes
    • compareTo

      public int compareTo(@NotNull @NotNull Path other)
      Specified by:
      compareTo in interface Comparable<Path>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object