public class TreeDetectionStrategy extends Object
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 and Description |
|---|
TreeDetectionStrategy() |
| Modifier and Type | Method and Description |
|---|---|
TreeDetectionStrategy |
addNodeNameRule(NodeNameRule nodeNameRule) |
TreeDetectionStrategy |
addRegexNodeNameRule(String pattern)
Adds a
RegexNodeNameRule so names matching the whole-name regular expression
collapse to wildcards. |
TreeDetectionStrategy |
addTransformer(int index,
TreeTransformer transformer) |
TreeDetectionStrategy |
addTransformer(TreeTransformer transformer) |
void |
apply(Tree tree)
Runs every
TreeTransformer against the supplied tree, in order. |
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. |
TreeDetectionStrategy |
clearNodeNameRules() |
TreeDetectionStrategy |
clearTransformers() |
TreeDetectionStrategy |
enableDateTimeNodeNames()
Adds a
DateTimeNodeNameRule so date/timestamp names collapse to wildcards. |
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. |
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. |
List<NodeNameRule> |
getNodeNameRules() |
List<TreeTransformer> |
getTransformers() |
boolean |
isOptimizeTreeStructure()
Indicates if dynamic names should collapse tree nodes together while the tree is being built
(default false).
|
boolean |
isWildcardPathSegment(String nodeName)
Indicates if any
NodeNameRule classifies the supplied name as dynamic. |
TreeDetectionStrategy |
setOptimizeTreeStructure(boolean optimizeTreeStructure) |
static TreeDetectionStrategy |
standard(boolean optimizeTreeStructure)
Returns the default strategy:
StandardNodeNameRule plus the
DetectFieldCandidates, DetectRecordBreakCandidates,
OptimizeTreeStructure (only when optimizeTreeStructure is set), and
MakeFieldNamesUnique passes. |
public static TreeDetectionStrategy standard(boolean optimizeTreeStructure)
StandardNodeNameRule plus the
DetectFieldCandidates, DetectRecordBreakCandidates,
OptimizeTreeStructure (only when optimizeTreeStructure is set), and
MakeFieldNamesUnique passes.public void apply(Tree tree)
TreeTransformer against the supplied tree, in order.public String canonicalizeNodeName(String nodeName)
*) when optimizeTreeStructure is
set and any NodeNameRule classifies the name as dynamic, otherwise the name
unchanged.public boolean isWildcardPathSegment(String nodeName)
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.public boolean isOptimizeTreeStructure()
public TreeDetectionStrategy setOptimizeTreeStructure(boolean optimizeTreeStructure)
public List<TreeTransformer> getTransformers()
public TreeDetectionStrategy addTransformer(TreeTransformer transformer)
public TreeDetectionStrategy addTransformer(int index, TreeTransformer transformer)
public TreeDetectionStrategy clearTransformers()
public List<NodeNameRule> getNodeNameRules()
public TreeDetectionStrategy addNodeNameRule(NodeNameRule nodeNameRule)
public TreeDetectionStrategy clearNodeNameRules()
public TreeDetectionStrategy enableSiblingPatternCollapse()
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.public TreeDetectionStrategy enableDateTimeNodeNames()
DateTimeNodeNameRule so date/timestamp names collapse to wildcards. Does
nothing if one is already present.public TreeDetectionStrategy addRegexNodeNameRule(String pattern)
RegexNodeNameRule so names matching the whole-name regular expression
collapse to wildcards. May be called multiple times with different expressions.public TreeDetectionStrategy enableStructureSiblingCollapse()
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.Copyright (c) 2006-2026 North Concepts Inc. All Rights Reserved.