java.lang.Object
com.northconcepts.datapipeline.foundations.pipeline.tree.detect.TreeDetectionStrategy

public class TreeDetectionStrategy extends Object
Defines the algorithms used to detect record breaks and fields in a Tree: an ordered list of NodeNameRules that classify dynamic element/field names while the tree is being built, followed by an ordered list of TreeTransformer passes that run over the loaded tree.

The default configuration (standard(boolean)) reproduces the behavior of Tree.loadXml(java.io.File, boolean) and Tree.loadJson(java.io.File, boolean). Both lists are editable to plug in custom algorithms:

 Tree tree = Tree.loadJson(file, TreeDetectionStrategy.standard(true).enableDateTimeNodeNames());
 
  • Constructor Details

    • TreeDetectionStrategy

      public TreeDetectionStrategy()
      Creates the same strategy as standard(false).
  • Method Details

    • standard

      public static TreeDetectionStrategy standard(boolean optimizeTreeStructure)
      Returns the default strategy: StandardNodeNameRule plus the DetectFieldCandidates, DetectRecordBreakCandidates, OptimizeTreeStructure (only when optimizeTreeStructure is set), and MakeFieldNamesUnique passes.
    • apply

      public void apply(Tree tree)
      Runs every TreeTransformer against the supplied tree, in order.
    • canonicalizeNodeName

      public String canonicalizeNodeName(String nodeName)
      Returns the node name used to key tree nodes while the tree is being built: the XPath wildcard (*) when optimizeTreeStructure is set and any NodeNameRule classifies the name as dynamic, otherwise the name unchanged.
    • isWildcardPathSegment

      public boolean isWildcardPathSegment(String nodeName)
      Indicates if any NodeNameRule classifies the supplied name as dynamic. Unlike canonicalizeNodeName(String), this check is not gated by optimizeTreeStructure; XPath expressions always collapse dynamic segments to wildcards.
    • isOptimizeTreeStructure

      public boolean isOptimizeTreeStructure()
      Indicates if dynamic names should collapse tree nodes together while the tree is being built (default false). This gates only node keying; it does not change the transformer list.
    • setOptimizeTreeStructure

      public TreeDetectionStrategy setOptimizeTreeStructure(boolean optimizeTreeStructure)
      Indicates if dynamic names should collapse tree nodes together while the tree is being built (default false); unlike standard(boolean), it does not add an OptimizeTreeStructure pass.
    • getTransformers

      public List<TreeTransformer> getTransformers()
      Returns the editable list of passes that apply(Tree) runs, in order.
    • addTransformer

      public TreeDetectionStrategy addTransformer(TreeTransformer transformer)
      Appends a pass to run after the existing ones.
    • addTransformer

      public TreeDetectionStrategy addTransformer(int index, TreeTransformer transformer)
      Inserts a pass at the given 0-based position in the run order.
    • clearTransformers

      public TreeDetectionStrategy clearTransformers()
      Removes all passes, including the standard detection passes.
    • getNodeNameRules

      public List<NodeNameRule> getNodeNameRules()
      Returns the editable list of rules that classify node names as dynamic.
    • addNodeNameRule

      public TreeDetectionStrategy addNodeNameRule(NodeNameRule nodeNameRule)
      Adds a rule that classifies node names as dynamic; a name is dynamic if any rule says so.
    • clearNodeNameRules

      public TreeDetectionStrategy clearNodeNameRules()
      Removes all node name rules, including the default StandardNodeNameRule.
    • enableSiblingPatternCollapse

      public TreeDetectionStrategy enableSiblingPatternCollapse()
      Inserts a CollapseSiblingPatterns pass ahead of the detection passes so siblings with a derivable naming pattern (for example item-1, item-2, item-3) collapse into one wildcard node. Does nothing if one is already present.
    • enableDateTimeNodeNames

      public TreeDetectionStrategy enableDateTimeNodeNames()
      Adds a DateTimeNodeNameRule so date/timestamp names collapse to wildcards. Does nothing if one is already present.
    • addRegexNodeNameRule

      public TreeDetectionStrategy addRegexNodeNameRule(String pattern)
      Adds a RegexNodeNameRule so names matching the whole-name regular expression collapse to wildcards. May be called multiple times with different expressions.
    • enableStructureSiblingCollapse

      public TreeDetectionStrategy enableStructureSiblingCollapse()
      Ensures a CollapseSiblingPatterns pass is present (inserting one ahead of the detection passes when missing) and that it includes a StructureSiblingSetRule, so structurally similar siblings collapse regardless of their names. Does nothing if one is already present.