Commit 9b7dfb28 authored by Nico Mack's avatar Nico Mack

Fixed an issue with apply method not visiting all rules

parent b4b1543f
...@@ -20,7 +20,6 @@ import org.slf4j.LoggerFactory; ...@@ -20,7 +20,6 @@ import org.slf4j.LoggerFactory;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Optional;
/** /**
* @author Nico Mack [nico.mack@list.lu] * @author Nico Mack [nico.mack@list.lu]
...@@ -39,6 +38,8 @@ public class RuleEngine { ...@@ -39,6 +38,8 @@ public class RuleEngine {
// * Constants // * Constants
// *************************************************************************** // ***************************************************************************
private static final String NEWLINE = System.lineSeparator();
private static final Logger LOGGER = LoggerFactory.getLogger(RuleEngine.class.getSimpleName()); private static final Logger LOGGER = LoggerFactory.getLogger(RuleEngine.class.getSimpleName());
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
...@@ -75,15 +76,21 @@ public class RuleEngine { ...@@ -75,15 +76,21 @@ public class RuleEngine {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public static boolean apply(InputEvent event) { public static boolean apply(InputEvent event) {
Optional<Rule> rule = rules.values().stream().filter(r -> r.apply(event)).findFirst(); // Optional<Rule> rule = rules.values().stream().filter(r -> r.apply(event)).findFirst();
return (rule.isPresent()); // return (rule.isPresent());
boolean fired = false;
for (Rule rule : rules.values()) {
fired |= rule.apply(event);
}
return fired;
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
public static String dump() { public static String dump() {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder(NEWLINE);
rules.values().forEach(r -> builder.append(r.toString()).append("\n")); rules.values().forEach(r -> builder.append(r.toString()).append(NEWLINE));
return builder.toString(); return builder.toString();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment