add weather tutorial

pull/130/merge
Mahmoud Ben Hassine 7 years ago
parent e2d0fbb517
commit d8211625b4

@ -149,6 +149,28 @@
</plugins>
</build>
</profile>
<profile>
<id>runWeatherTutorial</id>
<build>
<defaultGoal>exec:java</defaultGoal>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${maven-exec-plugin.version}</version>
<configuration>
<mainClass>org.jeasy.rules.tutorials.weather.Launcher</mainClass>
<systemProperties>
<systemProperty>
<key>java.util.logging.SimpleFormatter.format</key>
<value>[%1$tc] %4$s: %5$s%n</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>runShopTutorial</id>
<build>

@ -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…
Cancel
Save