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/lastNameis an absolute location. - The path
../customer/lastNameis a relative location that starts at the parent of the current node. - The paths
./customer/lastNameandcustomer/lastNameare both relative locations that start at the current (self) node and are equivalent.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabstract PathConcatenates this path instance with the path specified.abstract Pathabstract Pathabstract PathaddIndex(int index) Returns a path such that the last step is indexed with the specified number.abstract PathaddIndexedPath(Path aPath, int index) Concatenates this path instance with the specified indexed path.abstract PathaddIndexedStep(Step aStep, int index) Concatenates this path instance with the specified indexed step.abstract Stringformat()Returns the canonical string representation of this instance.abstract StepReturns the first step of this path,nullfor the root path.abstract StepReturns the last step of this path,nullfor the root path.abstract PathReturns this path without its last step.abstract intgetSize()Returns the number of steps in this path.abstract StepgetStep(int i) Returns the step at the specified position in this path.abstract Step[]getSteps()Returns the array of steps for this path.abstract PathgetSubPath(int beginIndex) Returns a new path that is a subpath of this path.abstract PathgetSubPath(int beginIndex, int endIndex) Returns a new path that is a subpath of this path.final booleanReturnstrueif thisPathidentifies a node in an aggregated list.abstract booleanReturnstrueif this path begins with '.' (self) or '..' (parent).abstract booleanisRoot()Returnstrueif this is the root path (whose canonical notation is "/").abstract booleanisSelf()Returnstrueif this is the self path (whose canonical notation is ".").static PathReturns the path based on the string specified.abstract PathresolveWith(Path aPath) Resolves the path specified against this instance by considering that this instance is the "current location".booleanstartsWith(Path aPath) Tests whether this path starts with the specified prefix.abstract booleanstartsWith(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, waitMethods 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:
thisaPathresult /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/addressand 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- ifindexis negative.- See Also:
-
addIndexedStep
Concatenates this path instance with the specified indexed step.For example, if this instance is
/customerand 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).aStepis already indexed.- Throws:
IllegalArgumentException- ifindexis negative.- See Also:
-
addIndexedPath
Concatenates this path instance with the specified indexed path.
For example, if this instance is
/itemand 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).aPathis already indexed.- Throws:
IllegalArgumentException- ifindexis negative.- See Also:
-
getFirstStep
Returns the first step of this path,nullfor the root path. -
resolveWith
Resolves the path specified against this instance by considering that this instance is the "current location".- Returns:
- if
aPathis absolute then it returnsaPath(no relative resolution); ifaPathis 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,nullfor 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 specifiedbeginIndexkey 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
SELFalways countsSELFas 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()Returnstrueif thisPathidentifies a node in an aggregated list. For example, the pathelement/item[0]/labelorelement/item/label[0]identifies a node under an aggregated list.- See Also:
-
isRelative
public abstract boolean isRelative()Returnstrueif this path begins with '.' (self) or '..' (parent). -
isRoot
public abstract boolean isRoot()Returnstrueif this is the root path (whose canonical notation is "/"). -
isSelf
public abstract boolean isSelf()Returnstrueif this is the self path (whose canonical notation is "."). -
format
Returns the canonical string representation of this instance.Examples:
/a/b/cis an absolute path notation,./a/b/cis the notation for a relative path starting with the self node,../a/b/cis the notation for a relative path starting with the parent node.- See Also:
-