Class Path
- All Implemented Interfaces:
Comparable<Path>
In string notation, the steps are separated by "/
" slashes. The syntax supported is in fact a
small subset of XPath:
- A path that begins with "
/
" is an absolute location, otherwise, it is a relative location. - Special steps are "
.
" (the self node) and "..
" (the parent node).
Examples
- The path
/domain/customer/lastName
is an absolute location. - The path
../customer/lastName
is a relative location that starts at the parent of the current node. - The paths
./customer/lastName
andcustomer/lastName
are both relative locations that start at the current (self) node and are equivalent.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract Path
Concatenates this path instance with the path specified.abstract Path
abstract Path
abstract Path
addIndex
(int index) Returns a path such that the last step is indexed with the specified number.abstract Path
addIndexedPath
(Path aPath, int index) Concatenates this path instance with the specified indexed path.abstract Path
addIndexedStep
(Step aStep, int index) Concatenates this path instance with the specified indexed step.abstract String
format()
Returns the canonical string representation of this instance.abstract Step
Returns the first step of this path,null
for the root path.abstract Step
Returns the last step of this path,null
for the root path.abstract Path
Returns this path without its last step.abstract int
getSize()
Returns the number of steps in this path.abstract Step
getStep
(int i) Returns the step at the specified position in this path.abstract Step[]
getSteps()
Returns the array of steps for this path.abstract Path
getSubPath
(int beginIndex) Returns a new path that is a subpath of this path.abstract Path
getSubPath
(int beginIndex, int endIndex) Returns a new path that is a subpath of this path.final boolean
Returnstrue
if thisPath
identifies a node in an aggregated list.abstract boolean
Returnstrue
if this path begins with '.' (self) or '..' (parent).abstract boolean
isRoot()
Returnstrue
if this is the root path (whose canonical notation is "/
").abstract boolean
isSelf()
Returnstrue
if this is the self path (whose canonical notation is ".
").static Path
Returns the path based on the string specified.abstract Path
resolveWith
(Path aPath) Resolves the path specified against this instance by considering that this instance is the "current location".boolean
startsWith
(Path aPath) Tests whether this path starts with the specified prefix.abstract boolean
startsWith
(Path aPath, int offset) Tests whether this path starts with the specified prefix beginning at specified index.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Comparable
compareTo
-
Field Details
-
ROOT
Corresponds to the path "/
". -
SELF
Corresponds to the path ".
". -
PARENT
Corresponds to the path "..
".
-
-
Method Details
-
parse
Returns the path based on the string specified.This method also performs path simplification whenever possible, if the path includes "
.
" or "..
". -
add
- See Also:
-
add
Concatenates this path instance with the path specified. This method also performs path simplification if the specified path begins with ".
" or "..
".Examples:
this
aPath
result /a/b/c /d/e /a/b/c/d/e /a/b/c . /a/b/c /a/b/c ./d/e /a/b/c/d/e /a/b/c ../d/e /a/b/d/e /a/b/c .. /a/b /a/b/c ../.. /a /a/b/c ../../.. / /a/b/c ../../../.. .. /a/b/c ../../../../d/e ../d/e /a/b/c ../../.. / . /a/b/c ./a/b/c . .. .. - See Also:
-
add
- See Also:
-
addIndex
Returns a path such that the last step is indexed with the specified number.
For example, if this instance is
/customer/address
and it receivesaddIndex(2)
, then the resulting path is/customer/address[2]
.This notation is only allowed on aggregated lists, not on tables. Contrary to the XPath specification, the index starts at 0 instead of 1.
- Throws:
IllegalStateException
- if the last step of this path is already indexed.IllegalArgumentException
- ifindex
is negative.- See Also:
-
addIndexedStep
Concatenates this path instance with the specified indexed step.For example, if this instance is
/customer
and it receivesaddIndexedStep(Step('address'),2)
, then the resulting path is/customer/address[2]
.This notation is only allowed on aggregated lists, not on tables. Contrary to the XPath specification, index starts at 0 instead of 1.
This method is equivalent to
@throws IllegalStateException ifadd(aStep).addIndex(index)
.
aStep
is already indexed.- Throws:
IllegalArgumentException
- ifindex
is negative.- See Also:
-
addIndexedPath
Concatenates this path instance with the specified indexed path.
For example, if this instance is
/item
and it receivesaddIndexedPath(Path('/customer/address'),2)
, then the resulting path is/item/customer/address[2]
.This notation is only allowed on aggregated lists, not on tables. Contrary to the XPath specification, index starts at 0 instead of 1.
This method is equivalent to
@throws IllegalStateException if the last step ofadd(aPath).addIndex(index)
.
aPath
is already indexed.- Throws:
IllegalArgumentException
- ifindex
is negative.- See Also:
-
getFirstStep
Returns the first step of this path,null
for the root path. -
resolveWith
Resolves the path specified against this instance by considering that this instance is the "current location".- Returns:
- if
aPath
is absolute then it returnsaPath
(no relative resolution); ifaPath
is relative then it returnsthis.add(aPath)
- See Also:
-
getStep
Returns the step at the specified position in this path. -
getSteps
Returns the array of steps for this path. -
getLastStep
Returns the last step of this path,null
for the root path. -
getPathWithoutLastStep
Returns this path without its last step.Examples and special cases:
- for
/a/b/c
, it returns/a/b
- for
/
, it returnsnull
- for
.
, it returns/
- for
..
, it returns/
- for
-
getSubPath
Returns a new path that is a subpath of this path. The subpath begins at the specified key and continues to the end of this path. -
getSubPath
Returns a new path that is a subpath of this path. The subpath begins at the specifiedbeginIndex
key and continues to the key at indexendIndex - 1
. Thus, the size of the subpath isendIndex - beginIndex
. -
startsWith
Tests whether this path starts with the specified prefix. -
startsWith
Tests whether this path starts with the specified prefix beginning at specified index. -
getSize
public abstract int getSize()Returns the number of steps in this path.A relative notation with
SELF
always countsSELF
as the first step. For example, for the notationa/b/c
, this method returns '4' since the path is interpreted as./a/b/c
. -
isIndexed
public final boolean isIndexed()Returnstrue
if thisPath
identifies a node in an aggregated list. For example, the pathelement/item[0]/label
orelement/item/label[0]
identifies a node under an aggregated list.- See Also:
-
isRelative
public abstract boolean isRelative()Returnstrue
if this path begins with '.' (self) or '..' (parent). -
isRoot
public abstract boolean isRoot()Returnstrue
if this is the root path (whose canonical notation is "/
"). -
isSelf
public abstract boolean isSelf()Returnstrue
if this is the self path (whose canonical notation is ".
"). -
format
Returns the canonical string representation of this instance.Examples:
/a/b/c
is an absolute path notation,./a/b/c
is the notation for a relative path starting with the self node,../a/b/c
is the notation for a relative path starting with the parent node.- See Also:
-