add air conditioning tutorial

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

@ -171,6 +171,28 @@
</plugins>
</build>
</profile>
<profile>
<id>runAircoTutorial</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.airco.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,24 @@
package org.jeasy.rules.tutorials.airco;
import org.jeasy.rules.annotation.Action;
import org.jeasy.rules.annotation.Condition;
import org.jeasy.rules.annotation.Fact;
import org.jeasy.rules.annotation.Rule;
import org.jeasy.rules.api.Facts;
@Rule(name = "air conditioning rule", description = "if it is hot, decrease temperature" )
public class AirConditioningRule {
@Condition
public boolean isItHot(@Fact("temperature") int temperature) {
return temperature > 25;
}
@Action
public void coolAir(Facts facts) {
System.out.println("It is hot! cooling air..");
Integer temperature = (Integer) facts.get("temperature");
facts.put("temperature", temperature - 1);
}
}

@ -0,0 +1,25 @@
package org.jeasy.rules.tutorials.airco;
import org.jeasy.rules.api.Facts;
import org.jeasy.rules.api.Rules;
import org.jeasy.rules.api.RulesEngine;
import org.jeasy.rules.core.InferenceRulesEngine;
public class Launcher {
public static void main(String[] args) {
// define facts
Facts facts = new Facts();
facts.put("temperature", 30);
// define rules
AirConditioningRule airConditioningRule = new AirConditioningRule();
Rules rules = new Rules();
rules.register(airConditioningRule);
// fire rules on known facts
RulesEngine rulesEngine = new InferenceRulesEngine();
rulesEngine.fire(rules, facts);
}
}
Loading…
Cancel
Save