Class DecisionTree
java.lang.Object
com.northconcepts.datapipeline.foundations.core.Bean
com.northconcepts.datapipeline.foundations.core.FoundationObject
com.northconcepts.datapipeline.foundations.decisiontree.DecisionTreeObject
com.northconcepts.datapipeline.foundations.decisiontree.DecisionTree
- All Implemented Interfaces:
DataExceptionContributor,JsonSerializable,RecordSerializable,XmlSerializable,Serializable
Evaluates a record by walking from the root node, at each node entering the first child whose condition holds (or else
the default node), and combines the outcomes of every node visited.
- See Also:
-
Field Summary
Fields inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
internalId, internalName, log, TIMESTAMP_FORMATFields 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 TypeMethodDescriptionaddExceptionProperties(DataException exception) Adds this object's current state to aDataException.addField(CalculatedField field) Adds a calculated field, evaluated before the tree is walked and available to it as a variable.Adds a calculated field that setsvariableto the value ofexpressionbefore the tree is walked.addField(Collection<CalculatedField> fields) Adds calculated fields, evaluated before the tree is walked and available to it as variables.Throws aDataExceptionif this object is invalid, otherwise returns it; the base implementation checks nothing.evaluate(ExpressionContext expressionContext) Evaluates the calculated fields, then walks the tree from the root node and returns the path taken and the combined outcome fields; outcomes of deeper nodes replace same-named fields set by earlier ones.Loads this object's state from the given JSON text.fromRecord(Record source) Loads this instance's state from a record and returnsthis(for fluid API call chaining).fromXml(InputStream inputStream) Parses the XML in the stream and loads this object's state from its root element.fromXmlElement(Element element) Returns the calculated fields, evaluated in order before the tree is walked and available to it as variables.getName()DefaultExpressionContextReturns the context holding the constants set withsetValue(String, Object).Returns the node where evaluation starts; its condition is not evaluated.longReturns the current row number, incremented for each evaluation and available to expressions asrownum.setDescription(String description) setRootNode(DecisionTreeNode rootNode) Sets the node where evaluation starts; its condition is not evaluated.Adds a constant that the tree's field, condition and outcome expressions can use.Adds a constant of the given type that the tree's field, condition and outcome expressions can use.toRecord()Converts this object's state to a record thatRecordSerializable.fromRecord(Record)can load.Writes this object as indented XML, without a declaration, to the writer and then closes it.toXmlElement(Document document) Returns an element, created withdocument, describing this object; the default implementation throws aDataException.voidvisit(DecisionTreeVisitor visitor) Calls the visitor for every node, depth-first from the root, visiting each node's children before its default node.Methods inherited from class com.northconcepts.datapipeline.foundations.core.FoundationObject
assertValid, clone, exception, exception, exception, getInternalId, getInternalName, resetInternalIdMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.northconcepts.datapipeline.core.DataExceptionContributor
addExceptionPropertiesMethods inherited from interface com.northconcepts.datapipeline.core.RecordSerializable
fromJson, toJson, toJson, toJson
-
Constructor Details
-
DecisionTree
public DecisionTree()
-
-
Method Details
-
visit
Calls the visitor for every node, depth-first from the root, visiting each node's children before its default node. -
getName
-
setName
-
getDescription
-
setDescription
-
getRootNode
Returns the node where evaluation starts; its condition is not evaluated. -
setRootNode
Sets the node where evaluation starts; its condition is not evaluated. -
getRootExpressionContext
public DefaultExpressionContext getRootExpressionContext()Returns the context holding the constants set withsetValue(String, Object). -
setValue
Adds a constant that the tree's field, condition and outcome expressions can use. -
setValue
Adds a constant of the given type that the tree's field, condition and outcome expressions can use. -
getFields
Returns the calculated fields, evaluated in order before the tree is walked and available to it as variables. -
addField
Adds calculated fields, evaluated before the tree is walked and available to it as variables. -
addField
Adds a calculated field that setsvariableto the value ofexpressionbefore the tree is walked. -
addField
-
addField
Adds a calculated field, evaluated before the tree is walked and available to it as a variable. -
getRownum
public long getRownum()Returns the current row number, incremented for each evaluation and available to expressions asrownum. -
assertValid
Description copied from class:FoundationObjectThrows aDataExceptionif this object is invalid, otherwise returns it; the base implementation checks nothing.- Overrides:
assertValidin classFoundationObject
-
evaluate
Evaluates the calculated fields, then walks the tree from the root node and returns the path taken and the combined outcome fields; outcomes of deeper nodes replace same-named fields set by earlier ones. -
addExceptionProperties
Description copied from class:FoundationObjectAdds this object's current state to aDataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.- Specified by:
addExceptionPropertiesin interfaceDataExceptionContributor- Overrides:
addExceptionPropertiesin classFoundationObject
-
toXml
Description copied from interface:XmlSerializableWrites this object as indented XML, without a declaration, to the writer and then closes it. -
fromXml
Description copied from interface:XmlSerializableParses the XML in the stream and loads this object's state from its root element. -
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.
-
fromJson
Description copied from interface:JsonSerializableLoads this object's state from the given JSON text. -
toXmlElement
Description copied from interface:XmlSerializableReturns an element, created withdocument, describing this object; the default implementation throws aDataException. -
fromXmlElement
-