Class Path
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.document.Path
-
- All Implemented Interfaces:
java.lang.Comparable<Path>,org.apache.jackrabbit.oak.cache.CacheValue
public final class Path extends java.lang.Object implements org.apache.jackrabbit.oak.cache.CacheValue, java.lang.Comparable<Path>
ThePathclass is closely modeled after the semantics ofPathUtilsin oak-commons. Corresponding methods in this class can be used as a replacement for the methods inPathUtilsonPathobjects.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(@NotNull Path other)@NotNull java.lang.Iterable<java.lang.String>elements()Returns the names of the path elements with increasinggetDepth()starting at depth 1.booleanequals(java.lang.Object obj)static @NotNull PathfromString(@NotNull java.lang.String path)Creates aPathfrom aString.@NotNull PathgetAncestor(int nth)Get the nth ancestor of a path.intgetDepth()The depth of this path.intgetMemory()@NotNull java.lang.StringgetName()Returns the name of this path.@Nullable PathgetParent()The parent of this path ornullif this path does not have a parent.inthashCode()booleanisAbsolute()booleanisAncestorOf(@NotNull Path other)Returntrueifthispath is an ancestor of theotherpath, otherwisefalse.booleanisRoot()intlength()java.lang.StringtoString()@NotNull java.lang.StringBuildertoStringBuilder(@NotNull java.lang.StringBuilder sb)Appends theStringrepresentation of thisPathto the passedStringBuilder.
-
-
-
Field Detail
-
ROOT
public static final Path ROOT
-
-
Constructor Detail
-
Path
public Path(@NotNull @NotNull Path parent, @NotNull @NotNull java.lang.String name)Creates a newPathfrom the given parentPath. The name of the newPathcannot be the emptyString.- Parameters:
parent- the parentPath.name- the name of the newPath.- Throws:
java.lang.IllegalArgumentException- if thenameis empty.
-
Path
public Path(@NotNull @NotNull java.lang.String name)Creates a relative path with a single name element. The name cannot be the emptyString.- Parameters:
name- the name of the first path element.- Throws:
java.lang.IllegalArgumentException- if thenameis empty.
-
-
Method Detail
-
getName
@NotNull public @NotNull java.lang.String getName()
Returns the name of this path. TheROOTis the only path with an empty name. That is a String with length zero.- Returns:
- the name of this path.
-
elements
@NotNull public @NotNull java.lang.Iterable<java.lang.String> elements()
Returns the names of the path elements with increasinggetDepth()starting at depth 1.- Returns:
- the names of the path elements.
-
isRoot
public boolean isRoot()
- Returns:
- whether this is the
ROOTpath.
-
getParent
@Nullable public @Nullable Path getParent()
The parent of this path ornullif this path does not have a parent. TheROOTpath and the first path element of a relative path do not have a parent.- Returns:
- the parent of this path or
nullif this path does not have a parent.
-
length
public int length()
- Returns:
- the number of characters of the
Stringrepresentation of this path.
-
getDepth
public int getDepth()
The depth of this path. TheROOThas a depth of 0. The path/foo/baras well asbar/bazhave 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)Returntrueifthispath is an ancestor of theotherpath, otherwisefalse.- Parameters:
other- the other path.- Returns:
- whether this path is an ancestor of the other path.
-
isAbsolute
public boolean isAbsolute()
- Returns:
trueif this is an absolute path;falseotherwise.
-
fromString
@NotNull public static @NotNull Path fromString(@NotNull @NotNull java.lang.String path) throws java.lang.IllegalArgumentException
Creates aPathfrom aString.- Parameters:
path- theStringto parse.- Returns:
- the
Pathfrom theString. - Throws:
java.lang.IllegalArgumentException- if thepathis the emptyString.
-
toStringBuilder
@NotNull public @NotNull java.lang.StringBuilder toStringBuilder(@NotNull @NotNull java.lang.StringBuilder sb)- Parameters:
sb- theStringBuilderthisPathis appended to.- Returns:
- the passed
StringBuilder.
-
getMemory
public int getMemory()
- Specified by:
getMemoryin interfaceorg.apache.jackrabbit.oak.cache.CacheValue
-
compareTo
public int compareTo(@NotNull @NotNull Path other)- Specified by:
compareToin interfacejava.lang.Comparable<Path>
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-