Class JsonNodeData

java.lang.Object
edu.cnu.mdi.json.JsonNodeData

public final class JsonNodeData extends Object
Immutable value object carried as the user-object of every DefaultMutableTreeNode in the JSON tree.

Purpose

Rather than encoding type information in the label string and re-parsing it in the renderer, each node carries an explicit JsonNodeData.Kind tag. This lets JsonTreeCellRenderer select colors in a single switch without any string analysis.

Label format

toString() returns the string that JsonTreeCellRenderer passes to the underlying label. The format is:

  • Leaf nodes with a key — key: value (e.g. name: "Alice", count: 42)
  • Non-leaf key/index nodes — key summary (e.g. address {3 keys}, [0] [2 items])
  • Root node — the file name
  • Top-level primitives (no key) — the value string alone
  • Field Details

    • key

      public final String key
      The key or array index label.

      Empty for top-level primitive nodes that have no enclosing key.

    • value

      public final String value
      The value string for leaf nodes, or a size summary (e.g. {3 keys}) for non-leaf key/index nodes.

      Empty for the root node.

    • kind

      public final JsonNodeData.Kind kind
      The token kind, used by JsonTreeCellRenderer to pick a color without re-parsing the label.
  • Constructor Details

    • JsonNodeData

      public JsonNodeData(String key, String value, JsonNodeData.Kind kind)
      Create a JsonNodeData.
      Parameters:
      key - key or array index; may be empty but not null
      value - value string or size summary; may be empty but not null
      kind - token kind; must not be null
  • Method Details

    • toString

      public String toString()
      Returns the display string used by JsonTreeCellRenderer.
      • Root: just the key (the file name).
      • No key (top-level primitive): just the value.
      • Otherwise: "key: value" for leaves or "key summary" for non-leaf keys.
      Overrides:
      toString in class Object
      Returns:
      the display string for this node