java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.pipeline.tree.Tree
All Implemented Interfaces:
DataExceptionContributor, JsonSerializable, RecordSerializable, XmlSerializable, Serializable

public class Tree extends Bean
Summarizes the structure of an XML or JSON document as a tree of TreeNodes, one per distinct path, and detects which nodes are record breaks and fields.
See Also:
  • Constructor Details

  • Method Details

    • loadXml

      public static Tree loadXml(File file)
      Loads an XML file and detects its record breaks and fields using standard(false).
    • loadXml

      public static Tree loadXml(Reader reader)
      Loads an XML document and detects its record breaks and fields using standard(false).
    • loadJson

      public static Tree loadJson(File file)
      Loads a JSON file and detects its record breaks and fields using standard(false).
    • loadJson

      public static Tree loadJson(Reader reader)
      Loads a JSON document and detects its record breaks and fields using standard(false).
    • loadXml

      public static Tree loadXml(File file, boolean optimizeTreeStructure)
      Loads an XML file using TreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes when optimizeTreeStructure is true.
    • loadXml

      public static Tree loadXml(Reader reader, boolean optimizeTreeStructure)
      Loads an XML document using TreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes when optimizeTreeStructure is true.
    • loadJson

      public static Tree loadJson(File file, boolean optimizeTreeStructure)
      Loads a JSON file using TreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes when optimizeTreeStructure is true.
    • loadJson

      public static Tree loadJson(Reader reader, boolean optimizeTreeStructure)
      Loads a JSON document using TreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes when optimizeTreeStructure is true.
    • loadXml

      public static Tree loadXml(File file, TreeDetectionStrategy detectionStrategy)
      Loads an XML file and detects its record breaks and fields using the given strategy, or standard(false) if null.
    • loadXml

      public static Tree loadXml(Reader reader, TreeDetectionStrategy detectionStrategy)
      Loads an XML document and detects its record breaks and fields using the given strategy, or standard(false) if null.
    • loadJson

      public static Tree loadJson(File file, TreeDetectionStrategy detectionStrategy)
      Loads a JSON file and detects its record breaks and fields using the given strategy, or standard(false) if null.
    • loadJson

      public static Tree loadJson(Reader reader, TreeDetectionStrategy detectionStrategy)
      Loads a JSON document and detects its record breaks and fields using the given strategy, or standard(false) if null.
    • getDetectionStrategy

      public TreeDetectionStrategy getDetectionStrategy()
      Returns the detection strategy; a tree without one, such as a deserialized tree, gets standard(false).
    • setDetectionStrategy

      public Tree setDetectionStrategy(TreeDetectionStrategy detectionStrategy)
      Sets the detection strategy, or standard(false) if null; nodes already loaded are not re-detected.
    • getRootNode

      public TreeNode getRootNode()
      Returns the unnamed root node whose children are the document's top-level nodes.
    • createFieldName

      public static String createFieldName(TreeNode node, Set<String> fieldNames)
      Builds a normalized field name for the supplied node that is unique within fieldNames (which this method adds it to): wildcard nodes use their name pattern hint or id, collisions gain the parent-name prefix and then a numeric suffix. Used by the field-naming detection passes.
    • normalizeFieldName

      public static String normalizeFieldName(String name)
      Trims the name, replaces hyphens, spaces and forward or back slashes with underscores and drops a leading @; returns null for null.
    • getAllFields

      public List<TreeNode> getAllFields()
      Returns the nodes marked as fields, depth-first with parents before their children.
    • getAllRecordBreaks

      public List<TreeNode> getAllRecordBreaks()
      Returns the nodes marked as record breaks, depth-first with parents before their children.
    • getAllNodes

      public List<TreeNode> getAllNodes()
      Returns every node, including the root, depth-first with parents before their children.
    • visit

      public void visit(boolean headFirst, Consumer<TreeNode> consumer)
      Passes every node, depth-first, to the consumer, visiting parents before their children when headFirst is true and after them otherwise.
    • 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 Bean
    • fromRecord

      public Tree 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 Bean
      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.
    • fromXmlElement

      public Tree fromXmlElement(Element element)