package wenrgise.workflow.utility;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import org.nfunk.jep.JEP;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.utility.EnrgiseUtil;

public class ConditionChecker {
  public double checkCondition(String ruleExpr, HashMap oVarMap, HashMap oVarType) throws EnrgiseSystemException, EnrgiseApplicationException {
    JEP myParser = new JEP();
    Set oVariableSet = oVarMap.keySet();
    Iterator oIt = oVariableSet.iterator();
    int count = 0;
    Object obj = null;
    while (oIt.hasNext()) {
      String varName = oIt.next();
      if (EnrgiseUtil.checkString((String)oVarType.get(varName))) {
        String varType = (String)oVarType.get(varName);
        if (varType.equalsIgnoreCase("S")) {
          obj = new String((String)oVarMap.get(varName));
        } else {
          obj = new Double((String)oVarMap.get(varName));
        } 
        System.out.println(varName);
        System.out.println(oVarMap.get(varName));
        myParser.addVariable(varName, obj);
      } 
    } 
    myParser.parseExpression(ruleExpr);
    System.out.println(String.valueOf("Val=").concat(String.valueOf(ruleExpr)));
    double oVal = myParser.getValue();
    System.out.println(String.valueOf("Val=").concat(String.valueOf(oVal)));
    return oVal;
  }
}
