java.lang.Object
dev.metaschema.databind.io.PathTracker
A lightweight utility for tracking the current path during parsing.
This class maintains a stack of path segments that can be pushed and popped as the parser descends into and ascends from nested elements. The current path can be retrieved at any time as a formatted string.
Path format:
- Empty stack: "/" (root)
- Single element: "/element"
- Nested elements: "/parent/child/grandchild"
This class is not thread-safe and should be used within a single parsing context.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear all segments from the path.Get the current path as a formatted string.intgetDepth()Get the depth of the current path (number of segments).booleanisEmpty()Check if the path is empty (at root level).pop()Pop the most recent segment from the path.voidPush a new segment onto the path.toString()
-
Constructor Details
-
PathTracker
public PathTracker()Construct a new empty path tracker.
-
-
Method Details
-
push
Push a new segment onto the path.- Parameters:
segment- the segment name to add, must not be null
-
pop
Pop the most recent segment from the path.- Returns:
- the removed segment, or null if the path was empty
-
getCurrentPath
Get the current path as a formatted string.Returns "/" for an empty path, or "/segment1/segment2/..." for nested paths.
- Returns:
- the current path string
-
getDepth
public int getDepth()Get the depth of the current path (number of segments).- Returns:
- the number of segments in the path
-
isEmpty
public boolean isEmpty()Check if the path is empty (at root level).- Returns:
- true if the path has no segments
-
clear
public void clear()Clear all segments from the path. -
toString
-