Class PathUtils

java.lang.Object
dev.omnist.document.PathUtils

public final class PathUtils extends Object
Shared utilities for constructing canonical document paths in diagnostics and report adjustments (omnist-spec ยง8).
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    childPath(String parentPath, String label, int index, int totalCount)
    Builds a canonical child path for an edge on a node.
    Precomputes the total occurrence counts for each label on a Node.
    static Object
    Groups repeated child edges into lists or single values for JSON, YAML, and TOML serialization.
    static boolean
    Detects whether grouping node's direct child edges by label (the transform every JSON-family writer -- JSON, YAML, TOML -- applies via groupEdges(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-spec format.interleaving-lost, Sec8.3.8).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • countLabels

      public static Map<String,Integer> countLabels(Node node)
      Precomputes the total occurrence counts for each label on a Node.
      Parameters:
      node - the node whose direct edges are counted
      Returns:
      a map from edge label to total count on this node
    • childPath

      public static String childPath(String parentPath, String label, int index, int totalCount)
      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]). When totalCount <= 1, the index is omitted (e.g. $.item).

      Parameters:
      parentPath - the path to the parent node (e.g. "$" or "$.user")
      label - the edge label
      index - the 0-based occurrence index of this edge among edges with the same label on this node
      totalCount - the total number of edges with this label on this node
      Returns:
      the canonical path string
    • groupEdges

      public static Object groupEdges(Object node)
      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

      public static boolean hasInterleavedLabels(Node node)
      Detects whether grouping node's direct child edges by label (the transform every JSON-family writer -- JSON, YAML, TOML -- applies via groupEdges(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-spec format.interleaving-lost, Sec8.3.8).
      Parameters:
      node - the node whose direct edges are checked
      Returns:
      true if grouping by label loses real cross-label interleaving