Class TreeNode
java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.pipeline.dataset.Column
com.northconcepts.datapipeline.foundations.pipeline.tree.TreeNode
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,Serializable
One distinct element, attribute or JSON path in a
Tree, with its instance count, value statistics and record-break and
field flags.- 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionInserts a new child with the given name at the 0-based index and returns the child.Moves the node from its current parent to the end of this node's children and returns it.Appends a new child with the given name and returns the child.protected ColumnaddXmlNode(XmlNode xmlNode) Counts one occurrence of the XML node at this path and records its XPath expression, value and attributes.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).fromXmlElement(Element element) 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 ifcreateis true, otherwise null is returned.getChildNode(XmlNode xmlNode, boolean create) Same asgetChildNode(String, boolean)using the XML node's local name; returns null if the node has no name.longReturns the total number of values held by the direct children.intgetDepth()Returns the number of ancestors above this node (0 for the root).longReturns the number of values held by this node and all its descendants.Returns the record field name for this node, or its node name if no field name is set.Returns the name of the nearest named ancestor, skipping wildcards and JSONobject/arraycontainers, or null if there is none.intReturns the number of times this path occurred in the document.intReturns the largest instance count among the children, or -1 if there are none; the result is cached untilinvalidateChildInstanceCountCache()is called.intReturns the smallest instance count among the children, or -1 if there are none; the result is cached untilinvalidateChildInstanceCountCache()is called.getName()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.Returns the naming pattern this (wildcard) node was collapsed down from, ornullwhen the node was not derived from a sibling-set pattern.Returns the parent node, or null if this is the root.Resets the lazily cachedgetMinimumChildInstanceCount()andgetMaximumChildInstanceCount()values so they are recomputed on next access.booleanIndicates if this node is an XML attribute, whose name starts with@.booleanIndicates if this field's value spans several records and should be repeated (cascaded) in each of them.booleanisField()Indicates if this node's values are read into a record field.booleanIndicates if this node held array values or is a JSONarraycontainer node.booleanIndicates if this node is a JSONobjectcontainer node.booleanIndicates if each instance of this node starts a new record.booleanIndicates if this node is named*, standing in for siblings with dynamic names.booleanremoveChild(TreeNode treeNode) Removes the child and clears its parent; returns false if it was not a child of this node.setCascadeFieldValue(boolean cascadeFieldValue) Indicates if this field's value spans several records and should be repeated (cascaded) in each of them.setChildren(List<TreeNode> children) Replaces the children with the given list (null for none) without updating the children's parent references.setField(boolean field) Indicates if this node's values are read into a record field.setFieldName(String fieldName) Sets the record field name for this node; if blank, the node name is used instead.setInstanceCount(int instanceCount) Sets the number of times this path occurred in the document.setNamePattern(SiblingSetPattern namePattern) Sets the naming pattern this wildcard node was collapsed down from; it is never serialized.Sets the parent reference only; useaddChild(TreeNode)to also add this node to the parent's children.setRecordBreak(boolean recordBreak) Indicates if each instance of this node starts a new record.setXpathExpression(String xpathExpression) 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 this node and its descendants, depth-first, to the consumer, visiting parents before their children whenheadFirstis true and after them otherwise; the consumer may change the children.Methods inherited from class com.northconcepts.datapipeline.foundations.pipeline.dataset.Column
addExceptionProperties, addField, addValue, getArrayValueCount, getAverageLength, getBestFitFieldType, getBestFitInferredFieldType, getBigNumberDescriptor, getBlankCount, getFieldType, getFieldTypeCount, getFieldTypes, getIndex, getInferredBooleanValueCount, getInferredFieldType, getInferredNumericValueCount, getInferredTemporalValueCount, getInferredTextualValueCount, getInferredTypeName, getInferredUuidValueCount, getLengthSum, getMaximumArrayElements, getMaximumLength, getMinimumArrayElements, getMinimumLength, getNonNullCount, getNonNullNonBlankCount, getNullCount, getNullValueFieldTypes, getNumberDescriptor, getSampleValue, getTemporalFieldTypeCount, getTemporalFieldTypes, getTemporalPatternCount, getTemporalPatterns, getUniqueValueCount, getUniqueValues, getUniqueValuesByCount, getValueCount, incBlankCount, incNullCount, isArray, isBoolean, isBoolean, isNumber, isNumeric, isTemporal, isTextual, isUuid, setBigNumberDescriptor, setBlankCount, setFieldTypes, setIndex, setLengthSum, setMaximumLength, setMinimumLength, setNullCount, setNullValueFieldTypes, setNumberDescriptor, setSampleValue, setTemporalFieldTypes, setTemporalPatterns, setValueCountMethods 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
-
TreeNode
public TreeNode() -
TreeNode
-
-
Method Details
-
isAttribute
public boolean isAttribute()Indicates if this node is an XML attribute, whose name starts with@. -
getParent
Returns the parent node, or null if this is the root. -
setParent
Sets the parent reference only; useaddChild(TreeNode)to also add this node to the parent's children. -
getChildren
-
getInstanceCount
public int getInstanceCount()Returns the number of times this path occurred in the document. -
setInstanceCount
Sets the number of times this path occurred in the document. -
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
Returns the child with the given name (ignoring case, after the tree's detection strategy canonicalizes it); a missing child is created ifcreateis true, otherwise null is returned. -
addChild
Moves the node from its current parent to the end of this node's children and returns it. -
removeFromParent
-
addChild
Appends a new child with the given name and returns the child. -
addChild
Inserts a new child with the given name at the 0-based index and returns the child. -
removeChild
Removes the child and clears its parent; returns false if it was not a child of this node. -
setChildren
Replaces the children with the given list (null for none) without updating the children's parent references. -
getChildNode
Same asgetChildNode(String, boolean)using the XML node's local name; returns null if the node has no name. -
visit
Passes this node and its descendants, depth-first, to the consumer, visiting parents before their children whenheadFirstis true and after them otherwise; the consumer may change the children. -
addXmlNode
Counts one occurrence of the XML node at this path and records its XPath expression, value and attributes. -
invalidateChildInstanceCountCache
Resets the lazily cachedgetMinimumChildInstanceCount()andgetMaximumChildInstanceCount()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 untilinvalidateChildInstanceCountCache()is called. -
getMaximumChildInstanceCount
public int getMaximumChildInstanceCount()Returns the largest instance count among the children, or -1 if there are none; the result is cached untilinvalidateChildInstanceCountCache()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
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
Indicates if this node's values are read into a record field. -
getNamePattern
Returns the naming pattern this (wildcard) node was collapsed down from, ornullwhen the node was not derived from a sibling-set pattern. Transient — never serialized. -
setNamePattern
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
Indicates if this field's value spans several records and should be repeated (cascaded) in each of them. -
getName
-
setName
-
isJsonArray
public boolean isJsonArray()Indicates if this node held array values or is a JSONarraycontainer node. -
isJsonObject
public boolean isJsonObject()Indicates if this node is a JSONobjectcontainer node. -
getFieldNamePrefix
Returns the name of the nearest named ancestor, skipping wildcards and JSONobject/arraycontainers, or null if there is none. -
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
Returns the record field name for this node, or its node name if no field name is set. -
setFieldName
Sets the record field name for this node; if blank, the node name is used instead. -
getXpathExpression
-
setXpathExpression
-
toRecord
Description copied from interface:RecordSerializableConverts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.- Specified by:
toRecordin interfaceRecordSerializable- Overrides:
toRecordin classColumn
-
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 classColumn- Parameters:
source-- Returns:
- this instance.
-
toXmlElement
Description copied from interface:XmlSerializableReturns an element, created withdocument, describing this object; the default implementation throws aDataException.- Specified by:
toXmlElementin interfaceXmlSerializable- Overrides:
toXmlElementin classColumn
-
fromXmlElement
- Specified by:
fromXmlElementin interfaceXmlSerializable- Overrides:
fromXmlElementin classColumn
-