diff --git a/pom.xml b/pom.xml index ac0ba94..db94ebd 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.datamelt evaluator - 1.5.3-SNAPSHOT + 1.5.4-SNAPSHOT 17 diff --git a/src/main/java/com/datamelt/evaluate/check/EvaluationResult.java b/src/main/java/com/datamelt/evaluate/check/EvaluationResult.java index a226e5b..489d75c 100644 --- a/src/main/java/com/datamelt/evaluate/check/EvaluationResult.java +++ b/src/main/java/com/datamelt/evaluate/check/EvaluationResult.java @@ -1,15 +1,16 @@ package com.datamelt.evaluate.check; -import java.util.ArrayList; import java.util.List; public class EvaluationResult { - private final List> groupResults= new ArrayList<>(); + private final List> groupResults; + private boolean passed; - public void addGroupResult(GroupResult groupResult) + public EvaluationResult(List> groupResults) { - groupResults.add(groupResult); + this.groupResults = groupResults; + this.evaluate(); } public List> getGroupResults() @@ -18,6 +19,11 @@ public List> getGroupResults() } public boolean passed() + { + return passed; + } + + private void evaluate() { boolean result = false; if(!groupResults.isEmpty()) @@ -28,33 +34,30 @@ public boolean passed() result = combineResults(result, groupResults.get(i)); } } - return result; + passed = result; } - private boolean combineResults(boolean groupResult1, GroupResult groupResult2) + private boolean combineResults(boolean intermediateResult, GroupResult groupResult2) { switch (groupResult2.getConnectorToPreviousGroup()) { case AND -> { - return groupResult2.passed() && groupResult1; + return groupResult2.passed() && intermediateResult; } case OR -> { - return groupResult2.passed() || groupResult1; + return groupResult2.passed() || intermediateResult; } case NOT -> { - return !(groupResult2.passed() && groupResult1); + return !(groupResult2.passed() && intermediateResult); } case NOR -> { - return !(groupResult2.passed() || groupResult1); + return !(groupResult2.passed() || intermediateResult); } default -> throw new IllegalStateException("unexpected value: " + groupResult2.getConnectorToPreviousGroup()); } } - - - } diff --git a/src/main/java/com/datamelt/evaluate/check/Logic.java b/src/main/java/com/datamelt/evaluate/check/Logic.java index e4a4a90..2019a0a 100644 --- a/src/main/java/com/datamelt/evaluate/check/Logic.java +++ b/src/main/java/com/datamelt/evaluate/check/Logic.java @@ -29,12 +29,12 @@ public Group getGroup(String name) public EvaluationResult evaluate(T data) { - EvaluationResult evaluationResult = new EvaluationResult<>(); - for(Group group : getGroups()) - { - evaluationResult.addGroupResult(new GroupResult<>(group, data)); - } - return evaluationResult; + return new EvaluationResult<>( + getGroups() + .stream() + .map(group -> new GroupResult<>(group, data)) + .toList() + ); } public String getGroupConnectionLogic() diff --git a/src/test/java/com/datamelt/evaluate/check/LogicTest.java b/src/test/java/com/datamelt/evaluate/check/LogicTest.java index 89b2900..6a98d71 100644 --- a/src/test/java/com/datamelt/evaluate/check/LogicTest.java +++ b/src/test/java/com/datamelt/evaluate/check/LogicTest.java @@ -31,7 +31,7 @@ public void testLogicPassedUsingSingleRowObject() .build(); EvaluationResult evaluationResult = logic.evaluate(testRow); - assert(logic.evaluate(testRow).passed()); + assert(evaluationResult.passed()); } @Test