add methods to set rule properties with a fluent API

pull/130/merge
Mahmoud Ben Hassine 7 years ago
parent 1722b0dbb3
commit 1460d5f6c7

@ -26,6 +26,7 @@ package org.jeasy.rules.mvel;
import org.jeasy.rules.api.Action;
import org.jeasy.rules.api.Condition;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rule;
import org.jeasy.rules.core.BasicRule;
import java.util.ArrayList;
@ -42,37 +43,43 @@ public class MVELRule extends BasicRule {
private List<Action> actions = new ArrayList<>();
/**
* Create a new MVEL action.
* Create a new MVEL rule.
*/
public MVELRule() {
super(Rule.DEFAULT_NAME, Rule.DEFAULT_DESCRIPTION, Rule.DEFAULT_PRIORITY);
}
/**
* Create a new MVEL action.
* Set rule name.
*
* @param name of the rule
* @return this rule
*/
public MVELRule(String name) {
super(name);
public MVELRule name(String name) {
this.name = name;
return this;
}
/**
* Create a new MVEL action.
* @param name of the rule
* Set rule description.
*
* @param description of the rule
* @return this rule
*/
public MVELRule(String name, String description) {
super(name, description);
public MVELRule description(String description) {
this.description = description;
return this;
}
/**
* Create a new MVEL action.
* @param name of the rule
* @param description of the rule
* Set rule priority.
*
* @param priority of the rule
* @return this rule
*/
public MVELRule(String name, String description, int priority) {
super(name, description, priority);
public MVELRule priority(int priority) {
this.priority = priority;
return this;
}
/**

@ -32,7 +32,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class MVELRuleTest {
private Facts facts = new Facts();
private MVELRule mvelRule = new MVELRule("rn", "rd", 1);
private MVELRule mvelRule = new MVELRule().name("rn").description("rd").priority(1);
@Before
public void setUp() throws Exception {

Loading…
Cancel
Save