Android Open Source - Kite Exp4j Evaluator






From Project

Back to project page Kite.

License

The source code is released under:

Apache License

If you think the Android project Kite listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * /*from  w ww . j a va 2 s. com*/
 */
package com.efurture.kite.expression;

import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

import de.congrace.exp4j.ExpressionBuilder;

/**
 * exp4j implementation of evaluator. exp4j: http://www.objecthunter.net/exp4j/
 * @author gubaojian   email: gubaojian@163.com
 *  */
public class Exp4jEvaluator extends Evaluator{

  /* (non-Javadoc)
   * @see com.efurture.kite.expression.ExpressionProvider#evalInt(java.lang.String, java.util.Map)
   */
  @Override
  public int evalute(String expression, Map<String, Object> paramsMap){
    try {
      ExpressionBuilder builder = new ExpressionBuilder(expression);
      Set<Entry<String, Object>> entries = paramsMap.entrySet();
      for(Entry<String, Object> entry : entries){
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof Number) {
          Number num = (Number)value;
          builder.withVariable(key, num.doubleValue());
        }
      }
      return (int)builder.build().calculate();
    }
    catch (Exception e) {
      throw new EvaluatorException(e);
    }
  }
}




Java Source Code List

com.efurture.kite.Kite.java
com.efurture.kite.OnFinishLayoutListener.java
com.efurture.kite.example.KiteItemActivity.java
com.efurture.kite.example.MainActivity.java
com.efurture.kite.expression.EvaluatorException.java
com.efurture.kite.expression.EvaluatorManager.java
com.efurture.kite.expression.Evaluator.java
com.efurture.kite.expression.Exp4jEvaluator.java
com.efurture.kite.expression.MVEL2Evaluator.java
com.efurture.kite.layout.LayoutExtension.java
com.efurture.kite.param.ParamMap.java
com.efurture.kite.param.Params.java