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

com.deliveredtechnologies.rulebook.lang.RuleBookDefaultResultBuilder Maven / Gradle / Ivy

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

import com.deliveredtechnologies.rulebook.model.Auditor;
import com.deliveredtechnologies.rulebook.model.Rule;
import com.deliveredtechnologies.rulebook.model.RuleBook;
import com.deliveredtechnologies.rulebook.model.RuleBookAuditor;

import java.util.function.Consumer;

/**
 * Builds the portion of the RuleBook that specifies a default result value.
 */
public class RuleBookDefaultResultBuilder implements TerminatingRuleBookBuilder {

  private RuleBook _ruleBook;

  public RuleBookDefaultResultBuilder(RuleBook ruleBook) {
    this._ruleBook = ruleBook;
  }

  /**
   * Adds a rule to the RuleBook.
   * @param consumer  functional interface that supplies a RuleBookRuleBuilder for building a Rule
   * @return          a builder with the added Rule
   */
  public RuleBookAddRuleBuilder addRule(Consumer> consumer) {
    return new RuleBookAddRuleBuilder<>(_ruleBook, consumer);
  }

  /**
   * Adds a rule to the RuleBook.
   * @param rule  Rule to be added into the RuleBook
   * @param    the fact type of the Rule
   * @return      RuleBookBuilder with the added Rule
   */
  public  RuleBookAddRuleBuilder addRule(Rule rule) {
    return new RuleBookAddRuleBuilder<>(_ruleBook, rule);
  }

  /**
   * Decorates the RuleBook with {@link Auditor} functionality for rules auditing.
   * @return  a builder that can add rules
   */
  public RuleBookAddRuleBuilder asAuditor() {
    return new RuleBookAddRuleBuilder<>(new RuleBookAuditor<>(_ruleBook));
  }

  @Override
  public RuleBook build() {
    return _ruleBook;
  }
}