Class Path
java.lang.Object
org.apache.jackrabbit.oak.plugins.document.Path
- All Implemented Interfaces:
Comparable<Path>
,CacheValue
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 Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
elements()
Returns the names of the path elements with increasinggetDepth()
starting at depth 1.boolean
static @NotNull Path
fromString
(@NotNull String path) Creates aPath
from aString
.@NotNull Path
getAncestor
(int nth) Get the nth ancestor of a path.int
getDepth()
The depth of this path.int
The estimated amount of memory used by this object, in bytes.@NotNull String
getName()
Returns the name of this path.@Nullable Path
The parent of this path ornull
if this path does not have a parent.int
hashCode()
boolean
boolean
isAncestorOf
(@NotNull Path other) Returntrue
ifthis
path is an ancestor of theother
path, otherwisefalse
.boolean
isRoot()
int
length()
toString()
@NotNull StringBuilder
toStringBuilder
(@NotNull StringBuilder sb) Appends theString
representation of thisPath
to the passedStringBuilder
.
-
Field Details
-
ROOT
-
-
Constructor Details
-
Path
Creates a newPath
from the given parentPath
. The name of the newPath
cannot be the emptyString
.- Parameters:
parent
- the parentPath
.name
- the name of the newPath
.- Throws:
IllegalArgumentException
- if thename
is empty.
-
Path
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 thename
is empty.
-
-
Method Details
-
getName
Returns the name of this path. TheROOT
is the only path with an empty name. That is a String with length zero.- Returns:
- the name of this path.
-
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
ROOT
path.
-
getParent
The parent of this path ornull
if this path does not have a parent. TheROOT
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. TheROOT
has a depth of 0. The path/foo/bar
as well asbar/baz
have depth 2.- Returns:
- the depth of the path.
-
getAncestor
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
Returntrue
ifthis
path is an ancestor of theother
path, otherwisefalse
.- 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 aPath
from aString
.- Parameters:
path
- theString
to parse.- Returns:
- the
Path
from theString
. - Throws:
IllegalArgumentException
- if thepath
is the emptyString
.
-
toStringBuilder
- Parameters:
sb
- theStringBuilder
thisPath
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 interfaceCacheValue
- Returns:
- the estimated number of bytes
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Path>
-
toString
-
hashCode
public int hashCode() -
equals
-