Package com.streamconverter.path
Class TreePath
java.lang.Object
com.streamconverter.path.TreePath
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 Summary
Modifier and TypeMethodDescriptionboolean2つのTreePathが等しいかどうかをセグメントリストで比較する。static TreePathCreates a TreePath from a JSON path expression.static TreePathCreates a TreePath from an XML path expression.inthashCode()セグメントリストに基づくハッシュコードを返す。booleanChecks if current path matches the target path segmentsbooleanmatchesIgnoringArraySyntax(List<String> currentPath) Checks if current path matches after stripping array-index syntax from this path's segments.toString()Returns the original path expression.
-
Method Details
-
fromXml
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
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
Checks if current path matches the target path segments -
matchesIgnoringArraySyntax
Checks if current path matches after stripping array-index syntax from this path's segments.A segment like
"orders[*]"or"orders[0]"is normalized to"orders"before comparison. This allows paths such as"$.orders[*].product_code"to match the streamingcurrentPathlist["orders", "product_code"].- Parameters:
currentPath- current path segments built by the streaming traversal- Returns:
- true if the normalized segments equal
currentPath
-
toString
Returns the original path expression. -
equals
2つのTreePathが等しいかどうかをセグメントリストで比較する。注意: 元のパス文字列(
toString()の値)が異なっていても、セグメントに展開した結果が同じであれば等しいとみなす。 例えば JSONスタイルの"$.user.name"と XMLスタイルの"user/name"がパース後に同じセグメントになる場合、 等しいと判定される。 -
hashCode
セグメントリストに基づくハッシュコードを返す。
-