Search in sources :

Example 16 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class Launcher method main.

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);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 17 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class SuspiciousRequestFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
    Facts facts = new Facts();
    facts.put("request", request);
    rulesEngine.fire(rules, facts);
    filterChain.doFilter(request, response);
}
Also used : Facts(org.jeasy.rules.api.Facts)

Example 18 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) {
    // define facts
    Facts facts = new Facts();
    facts.put("temperature", 30);
    // define rules
    Rule airConditioningRule = new RuleBuilder().name("air conditioning rule").when(itIsHot()).then(decreaseTemperature()).build();
    Rules rules = new Rules();
    rules.register(airConditioningRule);
    // fire rules on known facts
    RulesEngine rulesEngine = new InferenceRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : InferenceRulesEngine(org.jeasy.rules.core.InferenceRulesEngine) InferenceRulesEngine(org.jeasy.rules.core.InferenceRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rule(org.jeasy.rules.api.Rule) RuleBuilder(org.jeasy.rules.core.RuleBuilder) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 19 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class FizzBuzzWithEasyRules method main.

public static void main(String[] args) {
    // create rules engine
    RulesEngineParameters parameters = new RulesEngineParameters().skipOnFirstAppliedRule(true);
    RulesEngine fizzBuzzEngine = new DefaultRulesEngine(parameters);
    // create rules
    Rules rules = new Rules();
    rules.register(new FizzRule());
    rules.register(new BuzzRule());
    rules.register(new FizzBuzzRule(new FizzRule(), new BuzzRule()));
    rules.register(new NonFizzBuzzRule());
    // fire rules
    Facts facts = new Facts();
    for (int i = 1; i <= 100; i++) {
        facts.put("number", i);
        fizzBuzzEngine.fire(rules, facts);
        System.out.println();
    }
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) RulesEngineParameters(org.jeasy.rules.core.RulesEngineParameters) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Example 20 with Facts

use of org.jeasy.rules.api.Facts in project easy-rules by j-easy.

the class Launcher method main.

public static void main(String[] args) {
    // create facts
    Facts facts = new Facts();
    // create rules
    Rules rules = new Rules();
    rules.register(new HelloWorldRule());
    // create a rules engine and fire rules on known facts
    RulesEngine rulesEngine = new DefaultRulesEngine();
    rulesEngine.fire(rules, facts);
}
Also used : DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) DefaultRulesEngine(org.jeasy.rules.core.DefaultRulesEngine) RulesEngine(org.jeasy.rules.api.RulesEngine) Rules(org.jeasy.rules.api.Rules) Facts(org.jeasy.rules.api.Facts)

Aggregations

Facts (org.jeasy.rules.api.Facts)23 Rules (org.jeasy.rules.api.Rules)16 RulesEngine (org.jeasy.rules.api.RulesEngine)13 Test (org.junit.Test)13 DefaultRulesEngine (org.jeasy.rules.core.DefaultRulesEngine)5 Method (java.lang.reflect.Method)2 Rule (org.jeasy.rules.annotation.Rule)2 Action (org.jeasy.rules.api.Action)2 Condition (org.jeasy.rules.api.Condition)2 File (java.io.File)1 Rule (org.jeasy.rules.api.Rule)1 InferenceRulesEngine (org.jeasy.rules.core.InferenceRulesEngine)1 RuleBuilder (org.jeasy.rules.core.RuleBuilder)1 RulesEngineParameters (org.jeasy.rules.core.RulesEngineParameters)1 MVELRule (org.jeasy.rules.mvel.MVELRule)1 Before (org.junit.Before)1