com.deliveredtechnologies.rulebook.lang.RuleBookAddRuleBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rulebook-core Show documentation
Show all versions of rulebook-core Show documentation
A simple and intuitive rules abstraction for Java
package com.deliveredtechnologies.rulebook.lang;
import com.deliveredtechnologies.rulebook.model.Rule;
import com.deliveredtechnologies.rulebook.model.RuleBook;
import java.util.function.Consumer;
/**
* Builds the portion of the RuleBook that adds rules.
*/
public class RuleBookAddRuleBuilder implements TerminatingRuleBookBuilder {
private RuleBook _ruleBook;
RuleBookAddRuleBuilder(RuleBook ruleBook) {
_ruleBook = ruleBook;
}
RuleBookAddRuleBuilder(RuleBook ruleBook, Consumer> consumer) {
this(ruleBook);
addRule(consumer);
}
RuleBookAddRuleBuilder(RuleBook ruleBook, Rule rule) {
this(ruleBook);
addRule(rule);
}
/**
* 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) {
consumer.accept(new RuleBookRuleBuilder<>(_ruleBook));
return this;
}
/**
* 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) {
_ruleBook.addRule(rule);
return this;
}
@Override
public RuleBook build() {
return _ruleBook;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy