Class Path
- java.lang.Object
-
- com.thoughtworks.xstream.io.path.Path
-
public class Path extends java.lang.ObjectRepresents a path to a single node in the tree.Two absolute paths can also be compared to calculate the relative path between them. A relative path can be applied to an absolute path to calculate another absolute path.
Note that the paths are normally XPath compliant, so can be read by other XPath engines. However,
toString()will select a node list whileexplicit()will always select an individual node. If the return type of the XPath evaluation is a node, the result will be the same, because XPath will then use the first element of the list. The following are examples of path expressions that the Path object supports:Note that the implementation does not take care if the paths are XPath compliant, it simply manages the values between the path separator. However, it normalizes the path if a path element ends with a selector for the first element (i.e. "[1]"). Those will be handled transparent i.e. two Paths are treated equal if one was created with path elements containing this selector and the other one without.
The following are examples of path expressions that the Path object supports:
- /
- /some/node
- /a/b/c/b/a
- /a/b[1]/c[1]/b[1]/a[1]
- /some[3]/node[2]/a
- ../../../another[3]/node
Example
Path a = new Path("/html/body/div[1]/table[2]/tr[3]/td/div"); Path b = new Path("/html/body/div/table[2]/tr[6]/td/form"); Path relativePath = a.relativeTo(b); // produces: "../../../tr[6]/td/form" Path c = a.apply(relativePath); // same as Path b.- See Also:
PathTracker
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String[]chunksprivate static PathDOTprivate java.lang.StringpathAsStringprivate java.lang.StringpathExplicit
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Pathapply(Path relativePath)private intdepthOfPathDivergence(java.lang.String[] path1, java.lang.String[] path2)booleanequals(java.lang.Object o)java.lang.Stringexplicit()inthashCode()booleanisAncestor(Path child)private java.lang.Stringnormalize(java.lang.String s, int start, int end)PathrelativeTo(Path that)java.lang.StringtoString()
-
-
-
Field Detail
-
chunks
private final java.lang.String[] chunks
-
pathAsString
private transient java.lang.String pathAsString
-
pathExplicit
private transient java.lang.String pathExplicit
-
DOT
private static final Path DOT
-
-
Method Detail
-
normalize
private java.lang.String normalize(java.lang.String s, int start, int end)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
explicit
public java.lang.String explicit()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
depthOfPathDivergence
private int depthOfPathDivergence(java.lang.String[] path1, java.lang.String[] path2)
-
isAncestor
public boolean isAncestor(Path child)
-
-