add weather tutorial
parent
e2d0fbb517
commit
d8211625b4
@ -0,0 +1,25 @@
|
||||
package org.jeasy.rules.tutorials.weather;
|
||||
|
||||
import org.jeasy.rules.api.Facts;
|
||||
import org.jeasy.rules.api.Rules;
|
||||
import org.jeasy.rules.api.RulesEngine;
|
||||
import org.jeasy.rules.core.DefaultRulesEngine;
|
||||
|
||||
public class Launcher {
|
||||
|
||||
public static void main(String[] args) {
|
||||
// define facts
|
||||
Facts facts = new Facts();
|
||||
facts.put("rain", true);
|
||||
|
||||
// define rules
|
||||
WeatherRule weatherRule = new WeatherRule();
|
||||
Rules rules = new Rules();
|
||||
rules.register(weatherRule);
|
||||
|
||||
// fire rules on known facts
|
||||
RulesEngine rulesEngine = new DefaultRulesEngine();
|
||||
rulesEngine.fire(rules, facts);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package org.jeasy.rules.tutorials.weather;
|
||||
|
||||
import org.jeasy.rules.annotation.Action;
|
||||
import org.jeasy.rules.annotation.Condition;
|
||||
import org.jeasy.rules.annotation.Fact;
|
||||
import org.jeasy.rules.annotation.Rule;
|
||||
|
||||
@Rule(name = "weather rule", description = "if it rains then take an umbrella" )
|
||||
public class WeatherRule {
|
||||
|
||||
@Condition
|
||||
public boolean itRains(@Fact("rain") boolean rain) {
|
||||
return rain;
|
||||
}
|
||||
|
||||
@Action
|
||||
public void takeAnUmbrella() {
|
||||
System.out.println("It rains, take an umbrella!");
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue