Class PathTracker

java.lang.Object
dev.metaschema.databind.io.PathTracker

public class PathTracker extends Object
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 Details

    • PathTracker

      public PathTracker()
      Construct a new empty path tracker.
  • Method Details

    • push

      public void push(@NonNull String segment)
      Push a new segment onto the path.
      Parameters:
      segment - the segment name to add, must not be null
    • pop

      @Nullable public String pop()
      Pop the most recent segment from the path.
      Returns:
      the removed segment, or null if the path was empty
    • getCurrentPath

      @NonNull public String 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

      public String toString()
      Overrides:
      toString in class Object