com.deliveredtechnologies.rulebook.lang.WhenRuleBuilder 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.FactMap;
import com.deliveredtechnologies.rulebook.NameValueReferableTypeConvertibleMap;
import com.deliveredtechnologies.rulebook.Result;
import com.deliveredtechnologies.rulebook.model.Rule;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Predicate;
/**
* Builds the portion of a Rule that is available in the languate on 'when'.
*/
public class WhenRuleBuilder {
private Rule _rule;
WhenRuleBuilder(Rule rule, Predicate> condition) {
_rule = rule;
_rule.setCondition(condition);
}
/**
* Adds a using constraint in the Rule that restricts the facts supplied to the subsequent 'then' action.
* @param factNames the fact names to be supplied to the subsequent 'then' action
* @return a builder the allows for the Rule to be built following the 'using' statement
*/
public UsingRuleBuilder using(String... factNames) {
return new UsingRuleBuilder(_rule, factNames);
}
/**
* Adds a then action into the Rule.
* @param action an action that the rule will execute based on the condition
* @return a builder that allows for the Rule to be built following the 'then' statement
*/
public ThenRuleBuilder then(Consumer> action) {
return new ThenRuleBuilder(_rule, action);
}
/**
* Addds a then action into the Rule.
* @param action an action that the rule will execute based on the condition; accepts facts and the result
* @return a builder that allows for the Rule to be built following the 'then' statement
*/
public ThenRuleBuilder then(BiConsumer, Result> action) {
return new ThenRuleBuilder(_rule, action);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy