package groovy.dsl;

import com.google.common.collect.Lists;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;

import java.util.List;

/**
 * Created by yangyongli on 01/11/2017.
 */
public class CheckRuleDsl {

    public static void main(String[] args) {
        List<String> rules = Lists.newArrayList();
        rules.add("S <= 10");
        rules.add("S + A <= 20");
        rules.add("S + A + BP <= 55");
        rules.add("C >= 5");

        Binding binding = new Binding();
        binding.setVariable("A", 20.0);
        binding.setVariable("B", 30.0);
        GroovyShell shell = new GroovyShell(binding);
        Object result = shell.evaluate("A * weightA + B * weightB");
        System.out.println(result);
    }
}

@@ -519,13 +519,92 @@
 le(%22
-A%22, 2
+S%22, 5.0);%0A        binding.setVariable(%22A%22, 5.0);%0A        binding.setVariable(%22BP%22, 3
 0.0)
@@ -637,32 +637,72 @@
 ble(%22B%22, 30.0);%0A
+        binding.setVariable(%22C%22, 30.0);%0A
         GroovySh
@@ -739,16 +739,56 @@
 nding);%0A
+        for (String rule : rules) %7B%0A    
         
@@ -822,38 +822,19 @@
 ate(
-%22A * weightA + B * weightB%22);%0A
+rule);%0A    
     
@@ -865,16 +865,26 @@
 esult);%0A
+        %7D%0A
     %7D%0A%7D%0A

check rule by groovy shell