Skip to content

Commit

Permalink
add methods to set rules engine parameters with a Fluent API
Browse files Browse the repository at this point in the history
  • Loading branch information
fmbenhassine committed Dec 17, 2017
1 parent 366e342 commit c2d9f3c
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ public void setPriorityThreshold(final int priorityThreshold) {
this.priorityThreshold = priorityThreshold;
}

public RulesEngineParameters priorityThreshold(final int priorityThreshold) {
setPriorityThreshold(priorityThreshold);
return this;
}

public boolean isSkipOnFirstAppliedRule() {
return skipOnFirstAppliedRule;
}
Expand All @@ -138,6 +143,11 @@ public void setSkipOnFirstAppliedRule(final boolean skipOnFirstAppliedRule) {
this.skipOnFirstAppliedRule = skipOnFirstAppliedRule;
}

public RulesEngineParameters skipOnFirstAppliedRule(final boolean skipOnFirstAppliedRule) {
setSkipOnFirstAppliedRule(skipOnFirstAppliedRule);
return this;
}

public boolean isSkipOnFirstNonTriggeredRule() {
return skipOnFirstNonTriggeredRule;
}
Expand All @@ -146,6 +156,11 @@ public void setSkipOnFirstNonTriggeredRule(final boolean skipOnFirstNonTriggered
this.skipOnFirstNonTriggeredRule = skipOnFirstNonTriggeredRule;
}

public RulesEngineParameters skipOnFirstNonTriggeredRule(final boolean skipOnFirstNonTriggeredRule) {
setSkipOnFirstNonTriggeredRule(skipOnFirstNonTriggeredRule);
return this;
}

public boolean isSkipOnFirstFailedRule() {
return skipOnFirstFailedRule;
}
Expand All @@ -154,6 +169,11 @@ public void setSkipOnFirstFailedRule(final boolean skipOnFirstFailedRule) {
this.skipOnFirstFailedRule = skipOnFirstFailedRule;
}

public RulesEngineParameters skipOnFirstFailedRule(final boolean skipOnFirstFailedRule) {
setSkipOnFirstFailedRule(skipOnFirstFailedRule);
return this;
}

@Override
public String toString() {
return "Engine parameters { " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ public void setup() throws Exception {
when(rule1.getPriority()).thenReturn(1);
when(rule1.evaluate(facts)).thenReturn(true);

RulesEngineParameters parameters = new RulesEngineParameters();
parameters.setPriorityThreshold(1);
RulesEngineParameters parameters = new RulesEngineParameters().priorityThreshold(1);
rulesEngine = new DefaultRulesEngine(parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class SkipOnFirstAppliedRuleTest extends AbstractTest {
@Before
public void setup() throws Exception {
super.setup();
RulesEngineParameters parameters = new RulesEngineParameters();
parameters.setSkipOnFirstAppliedRule(true);
RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
rulesEngine = new DefaultRulesEngine(parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class SkipOnFirstFailedRuleTest extends AbstractTest {
@Before
public void setup() throws Exception {
super.setup();
RulesEngineParameters parameters = new RulesEngineParameters();
parameters.setSkipOnFirstFailedRule(true);
RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstFailedRule(true);
rulesEngine = new DefaultRulesEngine(parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public class SkipOnFirstNonTriggeredRuleTest extends AbstractTest {
@Before
public void setup() throws Exception {
super.setup();
RulesEngineParameters parameters = new RulesEngineParameters();
parameters.setSkipOnFirstNonTriggeredRule(true);
RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstNonTriggeredRule(true);
rulesEngine = new DefaultRulesEngine(parameters);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@
public class FizzBuzzWithEasyRules {
public static void main(String[] args) {
// create rules engine
RulesEngineParameters parameters = new RulesEngineParameters();
parameters.setSkipOnFirstAppliedRule(true);
RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
RulesEngine fizzBuzzEngine = new DefaultRulesEngine(parameters);

// create rules
Expand Down

0 comments on commit c2d9f3c

Please sign in to comment.