Class Path
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.document.Path
-
- All Implemented Interfaces:
java.lang.Comparable<Path>
,CacheValue
public final class Path extends java.lang.Object implements CacheValue, java.lang.Comparable<Path>
ThePath
class is closely modeled after the semantics ofPathUtils
in oak-commons. Corresponding methods in this class can be used as a replacement for the methods inPathUtils
onPath
objects.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
compareTo(@NotNull Path other)
@NotNull java.lang.Iterable<java.lang.String>
elements()
Returns the names of the path elements with increasinggetDepth()
starting at depth 1.boolean
equals(java.lang.Object obj)
static @NotNull Path
fromString(@NotNull java.lang.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
getMemory()
The estimated amount of memory used by this object, in bytes.@NotNull java.lang.String
getName()
Returns the name of this path.@Nullable Path
getParent()
The parent of this path ornull
if this path does not have a parent.int
hashCode()
boolean
isAbsolute()
boolean
isAncestorOf(@NotNull Path other)
Returntrue
ifthis
path is an ancestor of theother
path, otherwisefalse
.boolean
isRoot()
int
length()
java.lang.String
toString()
@NotNull java.lang.StringBuilder
toStringBuilder(@NotNull java.lang.StringBuilder sb)
Appends theString
representation of thisPath
to 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 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:
java.lang.IllegalArgumentException
- if thename
is 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 thename
is empty.
-
-
Method Detail
-
getName
@NotNull public @NotNull java.lang.String 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
@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
ROOT
path.
-
getParent
@Nullable public @Nullable 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
@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)
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 java.lang.String path) throws java.lang.IllegalArgumentException
Creates aPath
from aString
.- Parameters:
path
- theString
to parse.- Returns:
- the
Path
from theString
. - Throws:
java.lang.IllegalArgumentException
- if thepath
is the emptyString
.
-
toStringBuilder
@NotNull public @NotNull java.lang.StringBuilder toStringBuilder(@NotNull @NotNull java.lang.StringBuilder sb)
- 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
public int compareTo(@NotNull @NotNull Path other)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Path>
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-