Class TreePath

java.lang.Object
com.streamconverter.path.TreePath
All Implemented Interfaces:
IPath<List<String>>

public class TreePath extends Object implements IPath<List<String>>
Represents a hierarchical path for tree-like data structures (JSON, XML).

This class handles parsing and matching of path expressions in both JSON-style ("$.user.name") and XML-style ("user/name") formats. It converts path expressions into hierarchical segments for efficient matching during data processing.

  • Method Details

    • fromXml

      public static TreePath fromXml(String xmlPath)
      Creates a TreePath from an XML path expression.
      Parameters:
      xmlPath - the XML path expression (e.g., "user/name")
      Returns:
      TreePath instance
      Throws:
      IllegalArgumentException - if xmlPath is null or invalid
    • fromJson

      public static TreePath fromJson(String jsonPath)
      Creates a TreePath from a JSON path expression.
      Parameters:
      jsonPath - the JSON path expression (e.g., "$.user.name")
      Returns:
      TreePath instance
      Throws:
      IllegalArgumentException - if jsonPath is null or invalid
    • matches

      public boolean matches(List<String> currentPath)
      Checks if current path matches the target path segments
      Specified by:
      matches in interface IPath<List<String>>
      Parameters:
      currentPath - current path segments to match against
      Returns:
      true if paths match exactly
    • toString

      public String toString()
      Returns the original path expression.
      Overrides:
      toString in class Object
      Returns:
      the original path expression
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object