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

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

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

import com.deliveredtechnologies.rulebook.model.AuditableRule;
import com.deliveredtechnologies.rulebook.model.GoldenRule;
import com.deliveredtechnologies.rulebook.model.Rule;
import com.deliveredtechnologies.rulebook.model.RuleBook;

/**
 * A chained builder for building a Rule in the context of a RuleBook that can be audited.
 */
public class RuleBookAuditableRuleBuilder {
  private RuleBook _ruleBook;
  private Class _ruleClass;
  private String _ruleName;

  RuleBookAuditableRuleBuilder(RuleBook ruleBook, Class ruleClass, String ruleName) {
    _ruleBook = ruleBook;
    _ruleClass = ruleClass;
    _ruleName = ruleName;
  }

  /**
   * Specifies the fact type
   * @param factType  the type of object that facts are restricted to in the Rule.
   * @param        the generic fact type
   * @return          RuleBookRuleWithFactTypeBuilder for building RuleBook Rules with a specific fact type
   */
  @SuppressWarnings("unchecked")
  public  RuleBookRuleWithFactTypeBuilder withFactType(Class factType) {
    Rule rule =
        new AuditableRule((Rule)RuleBuilder.create(_ruleClass).withFactType(factType).build(), _ruleName);
    _ruleBook.addRule(rule);
    return new RuleBookRuleWithFactTypeBuilder<>(rule);
  }

  /**
   * Specifies no fact type.
   * A generic Object type is used for the Rule's fact type.
   * @return RuleBookRuleWithFactTypeBuilder for building RuleBook Rules with a specific fact type
   */
  public RuleBookRuleWithFactTypeBuilder withNoSpecifiedFactType() {
    return withFactType(Object.class);
  }
}