All Implemented Interfaces:
DataExceptionContributor, JsonSerializable, RecordSerializable, XmlSerializable, Serializable

public class DecisionTree extends DecisionTreeObject
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:
  • Constructor Details

    • DecisionTree

      public DecisionTree()
  • Method Details

    • visit

      public void visit(DecisionTreeVisitor visitor)
      Calls the visitor for every node, depth-first from the root, visiting each node's children before its default node.
    • getName

      public String getName()
    • setName

      public DecisionTree setName(String name)
    • getDescription

      public String getDescription()
    • setDescription

      public DecisionTree setDescription(String description)
    • getRootNode

      public DecisionTreeNode getRootNode()
      Returns the node where evaluation starts; its condition is not evaluated.
    • setRootNode

      public DecisionTree setRootNode(DecisionTreeNode rootNode)
      Sets the node where evaluation starts; its condition is not evaluated.
    • getRootExpressionContext

      public DefaultExpressionContext getRootExpressionContext()
      Returns the context holding the constants set with setValue(String, Object).
    • setValue

      public DecisionTree setValue(String name, Object value)
      Adds a constant that the tree's field, condition and outcome expressions can use.
    • setValue

      public DecisionTree setValue(String name, Object value, Class<?> type)
      Adds a constant of the given type that the tree's field, condition and outcome expressions can use.
    • getFields

      public List<CalculatedField> getFields()
      Returns the calculated fields, evaluated in order before the tree is walked and available to it as variables.
    • addField

      public DecisionTree addField(Collection<CalculatedField> fields)
      Adds calculated fields, evaluated before the tree is walked and available to it as variables.
    • addField

      public DecisionTree addField(String variable, String expression)
      Adds a calculated field that sets variable to the value of expression before the tree is walked.
    • addField

      public DecisionTree addField(String variable, String expression, boolean includeInOutcome)
    • addField

      public DecisionTree addField(CalculatedField field)
      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 as rownum.
    • assertValid

      public DecisionTree assertValid()
      Description copied from class: FoundationObject
      Throws a DataException if this object is invalid, otherwise returns it; the base implementation checks nothing.
      Overrides:
      assertValid in class FoundationObject
    • evaluate

      public DecisionTreeResult 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.
    • addExceptionProperties

      public DataException addExceptionProperties(DataException exception)
      Description copied from class: FoundationObject
      Adds this object's current state to a DataException. Since this method is called whenever an exception is thrown, subclasses should override it to add their specific information.
      Specified by:
      addExceptionProperties in interface DataExceptionContributor
      Overrides:
      addExceptionProperties in class FoundationObject
    • toXml

      public DecisionTree toXml(Writer writer)
      Description copied from interface: XmlSerializable
      Writes this object as indented XML, without a declaration, to the writer and then closes it.
    • fromXml

      public DecisionTree fromXml(InputStream inputStream)
      Description copied from interface: XmlSerializable
      Parses the XML in the stream and loads this object's state from its root element.
    • toRecord

      public Record toRecord()
      Description copied from interface: RecordSerializable
      Converts this object's state to a record that RecordSerializable.fromRecord(Record) can load.
      Specified by:
      toRecord in interface RecordSerializable
      Overrides:
      toRecord in class Bean
    • fromRecord

      public DecisionTree fromRecord(Record source)
      Description copied from interface: RecordSerializable
      Loads this instance's state from a record and returns this (for fluid API call chaining). For fluid API call chaining, the overridden method should change the declared return type to its class.
      Specified by:
      fromRecord in interface RecordSerializable
      Overrides:
      fromRecord in class Bean
      Parameters:
      source -
      Returns:
      this instance.
    • fromJson

      public DecisionTree fromJson(String jsonString)
      Description copied from interface: JsonSerializable
      Loads this object's state from the given JSON text.
    • toXmlElement

      public Element toXmlElement(Document document)
      Description copied from interface: XmlSerializable
      Returns an element, created with document, describing this object; the default implementation throws a DataException.
    • fromXmlElement

      public DecisionTree fromXmlElement(Element element)