Package dev.omnist.document
Class PathUtils
java.lang.Object
dev.omnist.document.PathUtils
Shared utilities for constructing canonical document paths in diagnostics and report adjustments (omnist-spec ยง8).
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilds a canonical child path for an edge on a node.countLabels(Node node) Precomputes the total occurrence counts for each label on aNode.static ObjectgroupEdges(Object node) Groups repeated child edges into lists or single values for JSON, YAML, and TOML serialization.static booleanhasInterleavedLabels(Node node) Detects whether groupingnode's direct child edges by label (the transform every JSON-family writer -- JSON, YAML, TOML -- applies viagroupEdges(java.lang.Object)) would change their relative order: true when two or more distinct labels are present and at least one label's occurrences are not all contiguous in the original edge order (omnist-specformat.interleaving-lost, Sec8.3.8).
-
Method Details
-
countLabels
Precomputes the total occurrence counts for each label on aNode.- Parameters:
node- the node whose direct edges are counted- Returns:
- a map from edge label to total count on this node
-
childPath
Builds a canonical child path for an edge on a node.When
totalCount > 1, the 0-based index[index]is included on every occurrence, including the first (e.g.$.item[0],$.item[1]). WhentotalCount <= 1, the index is omitted (e.g.$.item).- Parameters:
parentPath- the path to the parent node (e.g."$"or"$.user")label- the edge labelindex- the 0-based occurrence index of this edge among edges with the same label on this nodetotalCount- the total number of edges with this label on this node- Returns:
- the canonical path string
-
groupEdges
Groups repeated child edges into lists or single values for JSON, YAML, and TOML serialization. Preserves the first-seen insertion order of edge labels.- Parameters:
node- the prepared tree node or scalar value- Returns:
- the grouped data structure (Maps/Lists/Scalars)
-
hasInterleavedLabels
Detects whether groupingnode's direct child edges by label (the transform every JSON-family writer -- JSON, YAML, TOML -- applies viagroupEdges(java.lang.Object)) would change their relative order: true when two or more distinct labels are present and at least one label's occurrences are not all contiguous in the original edge order (omnist-specformat.interleaving-lost, Sec8.3.8).- Parameters:
node- the node whose direct edges are checked- Returns:
trueif grouping by label loses real cross-label interleaving
-