Class Path
- 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>
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 Iterable<String>elements()Returns the names of the path elements with increasinggetDepth()starting at depth 1.booleanequals(Object obj)static @NotNull PathfromString(@NotNull String path)Creates aPathfrom aString.@NotNull PathgetAncestor(int nth)Get the nth ancestor of a path.intgetDepth()The depth of this path.intgetMemory()The estimated amount of memory used by this object, in bytes.@NotNull 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()StringtoString()@NotNull StringBuildertoStringBuilder(@NotNull 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 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:
IllegalArgumentException- if thenameis empty.
-
Path
public Path(@NotNull @NotNull 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:
IllegalArgumentException- if thenameis empty.
-
-
Method Detail
-
getName
@NotNull public @NotNull 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 Iterable<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 String path) throws IllegalArgumentException
Creates aPathfrom aString.- Parameters:
path- theStringto parse.- Returns:
- the
Pathfrom theString. - Throws:
IllegalArgumentException- if thepathis the emptyString.
-
toStringBuilder
@NotNull public @NotNull StringBuilder toStringBuilder(@NotNull @NotNull StringBuilder sb)
- Parameters:
sb- theStringBuilderthisPathis appended to.- Returns:
- the passed
StringBuilder.
-
getMemory
public int getMemory()
Description copied from interface:CacheValueThe estimated amount of memory used by this object, in bytes.- Specified by:
getMemoryin interfaceCacheValue- Returns:
- the estimated number of bytes
-
compareTo
public int compareTo(@NotNull @NotNull Path other)- Specified by:
compareToin interfaceComparable<Path>
-
-