Class PathTracker
java.lang.Object
com.thoughtworks.xstream.io.path.PathTracker
Maintains the current
Path as a stream is moved through.
Can be linked to a HierarchicalStreamWriter or
HierarchicalStreamReader by wrapping them with a
PathTrackingWriter or PathTrackingReader.
Example
PathTracker tracker = new PathTracker();
tracker.pushElement("table");
tracker.pushElement("tr");
tracker.pushElement("td");
tracker.pushElement("form");
tracker.popElement("form");
tracker.popElement("td");
tracker.pushElement("td");
tracker.pushElement("div");
Path path = tracker.getPath(); // returns "/table/tr/td[2]/div"
- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintdepth()Get the depth of the stack.getPath()Current Path in stream.Get the last path element from the stack.peekElement(int i) Get a path element from the stack.voidNotify the tracker that the stream has moved out of an element.voidpushElement(String name) Notify the tracker that the stream has moved into a new element.private voidresizeStacks(int newCapacity)
-
Field Details
-
pointer
private int pointer -
capacity
private int capacity -
pathStack
-
indexMapStack
-
currentPath
-
-
Constructor Details
-
PathTracker
public PathTracker() -
PathTracker
public PathTracker(int initialCapacity) - Parameters:
initialCapacity- Size of the initial stack of nodes (one level per depth in the tree). Note that this is only for optimizations - the stack will resize itself if it exceeds its capacity. If in doubt, use the other constructor.
-
-
Method Details
-
pushElement
Notify the tracker that the stream has moved into a new element.- Parameters:
name- Name of the element
-
popElement
public void popElement()Notify the tracker that the stream has moved out of an element. -
peekElement
Get the last path element from the stack.- Returns:
- the name of the path element
- Since:
- 1.4.2
-
peekElement
Get a path element from the stack.- Parameters:
i- path index- Returns:
- the name of the path element
- Throws:
ArrayIndexOutOfBoundsException- if the index is >= 0 or <= -depth()- Since:
- 1.4.2
-
depth
public int depth()Get the depth of the stack.- Returns:
- the stack depth
- Since:
- 1.4.2
-
resizeStacks
private void resizeStacks(int newCapacity) -
getPath
Current Path in stream.
-