JARE is just another rules engine! It is minimalistic library to provide a rules engine (JAREngine) to software clients. Clients are able to run individual rules or multiple rules using JAREngine.
Provide the class to the given method and feed the rule when you run it:
Rule rule = RuleBuilder.given(String.class)
.then(s -> System.out.println("Hello " + s));
rule.run("JARE");
With a when clause:
Rule rule = RuleBuilder.given(String.class)
.when(s -> "JARE".equals(s))
.then(s -> System.out.println("Hello " + s));
rule.run("JARE");
We can also run in the same statement:
StringBuilder test = new StringBuilder();
RuleBuilder.given(StringBuilder.class)
.when(s -> s.toString().isEmpty())
.then(s -> s.append("Hello JARE"))
.run(test);
System.out.println(test);
Let's throw an exception:
RuleBuilder.given(Boolean.class)
.when(Boolean::booleanValue)
.thenThrow(RuntimeException::new)
.run(true);
You can chain multiple rules and fire the engine:
JAREngine.feed("JARE")
.addRule(r -> r.when(String::isEmpty).then(s -> System.out.println("Oh no!")))
.addRule(r -> r.when(s -> !s.isEmpty()).then(s -> System.out.println("Hello " + s)))
.fire();
You can also feed the engine with multiple inputs using a List or variable arguments:
JAREngine.feed("JARE", "", "me")
.addRule(r -> r.when(String::isEmpty).then(s -> System.out.println("Oh no!")))
.addRule(r -> r.when(s -> !s.isEmpty()).then(s -> System.out.println("Hello " + s)))
.fire();
Thank you for using JARE!