Class Tree
java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.pipeline.tree.Tree
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,Serializable
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:
-
Field Summary
Fields inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
SERIALIZED_CLASS_NAME, TYPEFields inherited from interface com.northconcepts.datapipeline.core.XmlSerializable
XML_SERIALIZED_CLASS_NAME -
Constructor Summary
ConstructorsConstructorDescriptionTree()Creates an empty tree usingstandard(false).Tree(boolean optimizeTreeStructure) Creates an empty tree usingTreeDetectionStrategy.standard(boolean)with the given structure optimization flag.Tree(TreeDetectionStrategy detectionStrategy) Creates an empty tree using the given detection strategy, orstandard(false)if null. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateFieldName(TreeNode node, Set<String> fieldNames) Builds a normalized field name for the supplied node that is unique withinfieldNames(which this method adds it to): wildcard nodes use theirname patternhint orid, collisions gain the parent-name prefix and then a numeric suffix.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).fromXmlElement(Element element) Returns the nodes marked as fields, depth-first with parents before their children.Returns every node, including the root, depth-first with parents before their children.Returns the nodes marked as record breaks, depth-first with parents before their children.Returns the detection strategy; a tree without one, such as a deserialized tree, getsstandard(false).Returns the unnamed root node whose children are the document's top-level nodes.static TreeLoads a JSON file and detects its record breaks and fields usingstandard(false).static TreeLoads a JSON file usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true.static TreeloadJson(File file, TreeDetectionStrategy detectionStrategy) Loads a JSON file and detects its record breaks and fields using the given strategy, orstandard(false)if null.static TreeLoads a JSON document and detects its record breaks and fields usingstandard(false).static TreeLoads a JSON document usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true.static TreeloadJson(Reader reader, TreeDetectionStrategy detectionStrategy) Loads a JSON document and detects its record breaks and fields using the given strategy, orstandard(false)if null.static TreeLoads an XML file and detects its record breaks and fields usingstandard(false).static TreeLoads an XML file usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true.static TreeloadXml(File file, TreeDetectionStrategy detectionStrategy) Loads an XML file and detects its record breaks and fields using the given strategy, orstandard(false)if null.static TreeLoads an XML document and detects its record breaks and fields usingstandard(false).static TreeLoads an XML document usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true.static TreeloadXml(Reader reader, TreeDetectionStrategy detectionStrategy) Loads an XML document and detects its record breaks and fields using the given strategy, orstandard(false)if null.static StringnormalizeFieldName(String name) Trims the name, replaces hyphens, spaces and forward or back slashes with underscores and drops a leading@; returns null for null.setDetectionStrategy(TreeDetectionStrategy detectionStrategy) Sets the detection strategy, orstandard(false)if null; nodes already loaded are not re-detected.toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.toXmlElement(Document document) Returns an element, created withdocument, describing this object; the default implementation throws aDataException.voidPasses every node, depth-first, to the consumer, visiting parents before their children whenheadFirstis true and after them otherwise.Methods inherited from class com.northconcepts.datapipeline.foundations.core.Bean
addExceptionProperties, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.DataExceptionContributor
addExceptionProperties, exception, exception, exception
-
Constructor Details
-
Tree
public Tree(boolean optimizeTreeStructure) Creates an empty tree usingTreeDetectionStrategy.standard(boolean)with the given structure optimization flag. -
Tree
public Tree()Creates an empty tree usingstandard(false). -
Tree
Creates an empty tree using the given detection strategy, orstandard(false)if null.
-
-
Method Details
-
loadXml
Loads an XML file and detects its record breaks and fields usingstandard(false). -
loadXml
Loads an XML document and detects its record breaks and fields usingstandard(false). -
loadJson
Loads a JSON file and detects its record breaks and fields usingstandard(false). -
loadJson
Loads a JSON document and detects its record breaks and fields usingstandard(false). -
loadXml
Loads an XML file usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true. -
loadXml
Loads an XML document usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true. -
loadJson
Loads a JSON file usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true. -
loadJson
Loads a JSON document usingTreeDetectionStrategy.standard(boolean), which merges dynamically named nodes into wildcard nodes whenoptimizeTreeStructureis true. -
loadXml
Loads an XML file and detects its record breaks and fields using the given strategy, orstandard(false)if null. -
loadXml
Loads an XML document and detects its record breaks and fields using the given strategy, orstandard(false)if null. -
loadJson
Loads a JSON file and detects its record breaks and fields using the given strategy, orstandard(false)if null. -
loadJson
Loads a JSON document and detects its record breaks and fields using the given strategy, orstandard(false)if null. -
getDetectionStrategy
Returns the detection strategy; a tree without one, such as a deserialized tree, getsstandard(false). -
setDetectionStrategy
Sets the detection strategy, orstandard(false)if null; nodes already loaded are not re-detected. -
getRootNode
Returns the unnamed root node whose children are the document's top-level nodes. -
createFieldName
Builds a normalized field name for the supplied node that is unique withinfieldNames(which this method adds it to): wildcard nodes use theirname patternhint orid, collisions gain the parent-name prefix and then a numeric suffix. Used by the field-naming detection passes. -
normalizeFieldName
Trims the name, replaces hyphens, spaces and forward or back slashes with underscores and drops a leading@; returns null for null. -
getAllFields
Returns the nodes marked as fields, depth-first with parents before their children. -
getAllRecordBreaks
Returns the nodes marked as record breaks, depth-first with parents before their children. -
getAllNodes
Returns every node, including the root, depth-first with parents before their children. -
visit
Passes every node, depth-first, to the consumer, visiting parents before their children whenheadFirstis true and after them otherwise. -
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable- Overrides:
toRecordin classBean
-
fromRecord
Description copied from interface:RecordSerializableLoads this instance's state from a record and returnsthis(for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.- Specified by:
fromRecordin interfaceRecordSerializable- Overrides:
fromRecordin classBean- Parameters:
source-- Returns:
- this instance.
-
toXmlElement
Description copied from interface:XmlSerializableReturns an element, created withdocument, describing this object; the default implementation throws aDataException. -
fromXmlElement
-