All Implemented Interfaces:
DataExceptionContributor, JsonSerializable, RecordSerializable, XmlSerializable, Serializable

public class TreeNode extends Column
One distinct element, attribute or JSON path in a Tree, with its instance count, value statistics and record-break and field flags.
See Also:
  • Constructor Details

    • TreeNode

      public TreeNode()
    • TreeNode

      public TreeNode(Tree tree)
  • Method Details

    • isAttribute

      public boolean isAttribute()
      Indicates if this node is an XML attribute, whose name starts with @.
    • getParent

      public TreeNode getParent()
      Returns the parent node, or null if this is the root.
    • setParent

      public TreeNode setParent(TreeNode parent)
      Sets the parent reference only; use addChild(TreeNode) to also add this node to the parent's children.
    • getChildren

      public List<TreeNode> getChildren()
    • getInstanceCount

      public int getInstanceCount()
      Returns the number of times this path occurred in the document.
    • setInstanceCount

      public TreeNode setInstanceCount(int instanceCount)
      Sets the number of times this path occurred in the document.
    • incInstanceCount

      public TreeNode incInstanceCount()
    • getDepth

      public int getDepth()
      Returns the number of ancestors above this node (0 for the root).
    • isWildcard

      public boolean isWildcard()
      Indicates if this node is named *, standing in for siblings with dynamic names.
    • getChildNode

      public TreeNode getChildNode(String childName, boolean create)
      Returns the child with the given name (ignoring case, after the tree's detection strategy canonicalizes it); a missing child is created if create is true, otherwise null is returned.
    • addChild

      public TreeNode addChild(TreeNode treeNode)
      Moves the node from its current parent to the end of this node's children and returns it.
    • removeFromParent

      public TreeNode removeFromParent()
    • addChild

      public TreeNode addChild(String childName)
      Appends a new child with the given name and returns the child.
    • addChild

      public TreeNode addChild(int index, String childName)
      Inserts a new child with the given name at the 0-based index and returns the child.
    • removeChild

      public boolean removeChild(TreeNode treeNode)
      Removes the child and clears its parent; returns false if it was not a child of this node.
    • setChildren

      public TreeNode setChildren(List<TreeNode> children)
      Replaces the children with the given list (null for none) without updating the children's parent references.
    • getChildNode

      public TreeNode getChildNode(XmlNode xmlNode, boolean create)
      Same as getChildNode(String, boolean) using the XML node's local name; returns null if the node has no name.
    • visit

      public void visit(boolean headFirst, Consumer<TreeNode> consumer)
      Passes this node and its descendants, depth-first, to the consumer, visiting parents before their children when headFirst is true and after them otherwise; the consumer may change the children.
    • addXmlNode

      protected Column addXmlNode(XmlNode xmlNode)
      Counts one occurrence of the XML node at this path and records its XPath expression, value and attributes.
    • invalidateChildInstanceCountCache

      public TreeNode invalidateChildInstanceCountCache()
      Resets the lazily cached getMinimumChildInstanceCount() and getMaximumChildInstanceCount() values so they are recomputed on next access. Transformers that merge or restructure children must call this on affected nodes.
    • getMinimumChildInstanceCount

      public int getMinimumChildInstanceCount()
      Returns the smallest instance count among the children, or -1 if there are none; the result is cached until invalidateChildInstanceCountCache() is called.
    • getMaximumChildInstanceCount

      public int getMaximumChildInstanceCount()
      Returns the largest instance count among the children, or -1 if there are none; the result is cached until invalidateChildInstanceCountCache() is called.
    • getChildrenValueCount

      public long getChildrenValueCount()
      Returns the total number of values held by the direct children.
    • getDescendantValueCount

      public long getDescendantValueCount()
      Returns the number of values held by this node and all its descendants.
    • isRecordBreak

      public boolean isRecordBreak()
      Indicates if each instance of this node starts a new record.
    • setRecordBreak

      public TreeNode setRecordBreak(boolean recordBreak)
      Indicates if each instance of this node starts a new record.
    • isField

      public boolean isField()
      Indicates if this node's values are read into a record field.
    • setField

      public TreeNode setField(boolean field)
      Indicates if this node's values are read into a record field.
    • getNamePattern

      public SiblingSetPattern getNamePattern()
      Returns the naming pattern this (wildcard) node was collapsed down from, or null when the node was not derived from a sibling-set pattern. Transient — never serialized.
    • setNamePattern

      public TreeNode setNamePattern(SiblingSetPattern namePattern)
      Sets the naming pattern this wildcard node was collapsed down from; it is never serialized.
    • isCascadeFieldValue

      public boolean isCascadeFieldValue()
      Indicates if this field's value spans several records and should be repeated (cascaded) in each of them.
    • setCascadeFieldValue

      public TreeNode setCascadeFieldValue(boolean cascadeFieldValue)
      Indicates if this field's value spans several records and should be repeated (cascaded) in each of them.
    • getName

      public String getName()
      Overrides:
      getName in class Column
    • setName

      public Column setName(String name)
      Overrides:
      setName in class Column
    • isJsonArray

      public boolean isJsonArray()
      Indicates if this node held array values or is a JSON array container node.
    • isJsonObject

      public boolean isJsonObject()
      Indicates if this node is a JSON object container node.
    • getFieldNamePrefix

      public String getFieldNamePrefix()
      Returns the name of the nearest named ancestor, skipping wildcards and JSON object/array containers, or null if there is none.
    • getNamePath

      public String getNamePath()
      Returns the slash-separated names from the top of the tree down to this node, such as /orders/order/id, or null for the unnamed root.
    • getFieldName

      public String getFieldName()
      Returns the record field name for this node, or its node name if no field name is set.
    • setFieldName

      public TreeNode setFieldName(String fieldName)
      Sets the record field name for this node; if blank, the node name is used instead.
    • getXpathExpression

      public String getXpathExpression()
    • setXpathExpression

      public TreeNode setXpathExpression(String xpathExpression)
    • toRecord

      public Record toRecord()
      Description copied from interface: RecordSerializable
      Converts this object's state to a record that RecordSerializable.fromRecord(Record) can load.
      Specified by:
      toRecord in interface RecordSerializable
      Overrides:
      toRecord in class Column
    • fromRecord

      public TreeNode fromRecord(Record source)
      Description copied from interface: RecordSerializable
      Loads this instance's state from a record and returns this (for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.
      Specified by:
      fromRecord in interface RecordSerializable
      Overrides:
      fromRecord in class Column
      Parameters:
      source -
      Returns:
      this instance.
    • toXmlElement

      public Element toXmlElement(Document document)
      Description copied from interface: XmlSerializable
      Returns an element, created with document, describing this object; the default implementation throws a DataException.
      Specified by:
      toXmlElement in interface XmlSerializable
      Overrides:
      toXmlElement in class Column
    • fromXmlElement

      public TreeNode fromXmlElement(Element element)
      Specified by:
      fromXmlElement in interface XmlSerializable
      Overrides:
      fromXmlElement in class Column