Top Description Fields Constructors Methods
com.thoughtworks.xstream.io.path

public Class Path

extends Object
Class Inheritance
Imports
com.thoughtworks.xstream.core.util.FastStack, java.util.ArrayList, .List

Represents 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 while explicit() 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:

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.
Author
Joe Walnes
See Also
PathTracker

Field Summary

Modifier and TypeField and Description
private final String[]
private static final Path
private transient String
private transient String

Constructor Summary

AccessConstructor and Description
public
Path(String pathAsString)

public
Path(String[] chunks)

Method Summary

Modifier and TypeMethod and Description
public Path
apply(Path relativePath)

private int
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public String
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
private String
normalize(String s, int start, int end)

public Path
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

chunksback to summary
private final String[] chunks
DOTback to summary
private static final Path DOT
pathAsStringback to summary
private transient String pathAsString
pathExplicitback to summary
private transient String pathExplicit

Constructor Detail

Pathback to summary
public Path(String pathAsString)
Pathback to summary
public Path(String[] chunks)

Method Detail

applyback to summary
public Path apply(Path relativePath)
depthOfPathDivergenceback to summary
private int depthOfPathDivergence(String[] path1, String[] path2)
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

explicitback to summary
public String explicit()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

isAncestorback to summary
public boolean isAncestor(Path child)
normalizeback to summary
private String normalize(String s, int start, int end)
relativeToback to summary
public Path relativeTo(Path that)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.