All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deliveredtechnologies.rulebook.DecisionBook Maven / Gradle / Ivy

There is a newer version: 0.12
Show newest version
package com.deliveredtechnologies.rulebook;

import java.util.Optional;

/**
 * DecisionBook is a type of {@link RuleBook} that stores a return type linked to all the rules in the DecisionBook.
 */
@Deprecated
public abstract class DecisionBook extends RuleBook {
  private Result _result = new Result();

  /**
   * The withDefaultResult method allows a default result value to be specified.
   * When using the DSL syntax to chain calls, this method should be the first one specified.
   *
   * @param result the initial value of the stored result
   * @return the current DecisionBook object
   */
  public final DecisionBook withDefaultResult(U result) {
    _result.setValue(result);
    return this;
  }

  /**
   * The addRule() method allows a rule to be added to the DecisionBook in the abstract defineRules
   * method.
   * @param rule  the Decision rule to be added to the DecisionBook
   */
  public void addRule(Decision rule) {
    if (rule == null) {
      return;
    }

    super.addRule(rule);
    rule.setResult(_result);
  }

  /**
   * The getResult() method allows the result of the DecisionBook rules execution to be retrieved.
   * @return the stored result value
   */
  public U getResult() {
    return _result.getValue();
  }

}