当前位置: 首页>>代码示例>>Java>>正文


Java ExpressionEvaluator类代码示例

本文整理汇总了Java中org.codehaus.janino.ExpressionEvaluator的典型用法代码示例。如果您正苦于以下问题:Java ExpressionEvaluator类的具体用法?Java ExpressionEvaluator怎么用?Java ExpressionEvaluator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ExpressionEvaluator类属于org.codehaus.janino包,在下文中一共展示了ExpressionEvaluator类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
public ValidationAPI init(String validExpression,Map<String,String> fieldMap){
		String [] fields=new String[fieldMap.size()];
		Class [] types=new Class[fieldMap.size()];
		int index=0;
		try {
		for(String keys:fieldMap.keySet()){
				fields[index]=keys;
				types[index]=getType(fieldMap.get(keys));
			index++;
		}
			expressionEvaluator=new ExpressionEvaluator(
					packageNames + validExpression,
					Object.class,fields,types);

//			expressionEvaluator.setDefaultImports(listOfPackage.toArray(new String[listOfPackage.size()]));

			return this;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
 
开发者ID:capitalone,项目名称:Hydrograph,代码行数:22,代码来源:ValidationAPI.java

示例2: basicAddition

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
@Test
public void basicAddition() throws Exception{
  // set up an expression evaluator for setting the out field to the value of the sum of fields a and b.
  ExpressionEvaluator ee = new ExpressionEvaluator(
      "v.out = v.a + v.b",
      void.class,                     // expressionType
      new String[] { "v" },           // parameterNames
      new Class[] { Variables.class}  // parameterTypes
  );
  
  // define the input variable object.
  Variables v = new Variables(5, 10);
  
  // evaluate the expression.  void is response since we're putting the value back into the field.
  ee.evaluate(new Object[]{v});
  
  // check result.
  assertTrue(v.out == 15);
}
 
开发者ID:jacques-n,项目名称:oscon-drill,代码行数:20,代码来源:E1JaninoTest.java

示例3: janino

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
private int janino() throws Exception{
  // Compile the expression once; relatively slow.
  org.codehaus.janino.ExpressionEvaluator ee = new org.codehaus.janino.ExpressionEvaluator("c > d ? c : d", // expression
      int.class, // expressionType
      new String[] { "c", "d" }, // parameterNames
      new Class[] { int.class, int.class } // parameterTypes
  );

  // Evaluate it with varying parameter values; very fast.
  return (Integer) ee.evaluate(new Object[] { // parameterValues
      new Integer(10), new Integer(11), });
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:13,代码来源:TestClassCompilationTypes.java

示例4: jdk

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
private int jdk() throws Exception{
  // Compile the expression once; relatively slow.
  ExpressionEvaluator ee = new ExpressionEvaluator("c > d ? c : d", // expression
      int.class, // expressionType
      new String[] { "c", "d" }, // parameterNames
      new Class[] { int.class, int.class } // parameterTypes
  );

  // Evaluate it with varying parameter values; very fast.
  return  (Integer) ee.evaluate(new Object[] { // parameterValues
      new Integer(10), new Integer(11), });
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:13,代码来源:TestClassCompilationTypes.java

示例5: evaluate

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
/**
 * Evaluate expression with actual parameter values.
 * 
 * @param evaluator
 *          <code>ExpressionEvaluator</code>
 * @param mdcValues
 *          <code>List</code> a collection of the MDC values.
 * @return <code>int</code>
 */
private int evaluate(final ExpressionEvaluator evaluator,
		final List<Object> list) {
	int ret = DENY;
	if (evaluator != null && list != null && 0 < list.size()) {
		try {
			final Object object = evaluator.evaluate(list.toArray());
			ret = (object != null && (Boolean) object) ? NEUTRAL : DENY;
		} catch (InvocationTargetException e) {
			LOG.error(e);
		}
	}
	return ret;
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:23,代码来源:MDCFilter.java

示例6: testDecide

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
@Test
public void testDecide() {

  final String keys = "LoggedBy,MessageId";
  final String expression = "LoggedBy != null || MessageId != null";

  final List<Object> mdcValues = new ArrayList<Object>();
  final List<Class<String>> keyTypes = new ArrayList<Class<String>>();
  final String[] keyValues = keys.split(",");
  if (keyValues != null) {
    for (final String keyValue : keyValues) {
      final Object mdcValue = MDC.get(keyValue);
      keyTypes.add((Class<String>) keyValue.getClass());
      mdcValues.add(mdcValue);
    }
  }

  final ExpressionEvaluator evaluator = new ExpressionEvaluator();
  evaluator.setParameters(keyValues, keyTypes.toArray(new Class[0]));

  try {
    evaluator.cook(expression);
  } catch (Exception e) {
    LOG.error(e);
    fail(e.getMessage());
  }

  assertNotNull(evaluator);

  ExpressionCache.getInstance().put(expression, evaluator);

  ExpressionEvaluator testEvaluator = ExpressionCache.getInstance().get(
      expression);

  assertNotNull(testEvaluator);

  assertTrue(testEvaluator.equals(evaluator));

  ExpressionCache.getInstance().put(expression, evaluator);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:41,代码来源:ExpressionCacheTest.java

示例7: compile

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
public void compile(Class<?> jtype) throws CompileException {
	
	_eval = new ExpressionEvaluator(
		_expression,     // expression
		jtype, // expressionType
	    _params.toArray(new String[_params.size()]), // parameterNames
	    _classes.toArray(new Class<?>[_classes.size()])  // parameterTypes
	);
}
 
开发者ID:osbitools,项目名称:OsBiToolsWs,代码行数:10,代码来源:AbstractDataSet.java

示例8: ComplexExpr

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
public ComplexExpr(String expression)
{
    try
    {
        this.ee = new ExpressionEvaluator(expression, int.class, ARG_NAMES, ARG_TYPES);
    }
    catch (CompileException e)
    {
        throw new IllegalArgumentException("Failed to compile the given expression '" + expression + "' !", e);
    }
}
 
开发者ID:CubeEngine,项目名称:I18n,代码行数:12,代码来源:ComplexExpr.java

示例9: ExpressionCache

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
private ExpressionCache() {
	expCache = new HashMap<String, ExpressionEvaluator>();
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:4,代码来源:ExpressionCache.java

示例10: put

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
public synchronized void put(final String key, final ExpressionEvaluator value) {
	if ((!expCache.containsKey(key) || expCache.get(key) == null)
			&& value != null)
		expCache.put(key, value);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:6,代码来源:ExpressionCache.java

示例11: get

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
public ExpressionEvaluator get(final String key) {
	return expCache.get(key);
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:4,代码来源:ExpressionCache.java

示例12: calcFields

import org.codehaus.janino.ExpressionEvaluator; //导入依赖的package包/类
private boolean calcFields(RowMetaInterface rowMeta, Object[] r) throws KettleValueException
{
    try
    {
    	// Initialize evaluators etc.  Only do it once.
    	//
    	if (data.expressionEvaluator==null) {
    		data.argumentIndexes = new ArrayList<Integer>();
    		
    		List<String> parameterNames = new ArrayList<String>();
    		List<Class<?>> parameterTypes = new ArrayList<Class<?>>();

    		for (int i=0;i<data.outputRowMeta.size();i++) {

    			ValueMetaInterface valueMeta = data.outputRowMeta.getValueMeta(i);

    			
    			// See if the value is being used in a formula...
    			//
    			if (meta.getCondition().contains(valueMeta.getName())) {
    				// If so, add it to the indexes...
    				data.argumentIndexes.add(i);

    				Class<?> parameterType;
					switch(valueMeta.getType()) {
     			case ValueMetaInterface.TYPE_STRING    : parameterType = String.class; break;
     			case ValueMetaInterface.TYPE_NUMBER    : parameterType = Double.class; break;
     			case ValueMetaInterface.TYPE_INTEGER   : parameterType = Long.class; break;
     			case ValueMetaInterface.TYPE_DATE      : parameterType = Date.class; break;
     			case ValueMetaInterface.TYPE_BIGNUMBER : parameterType = BigDecimal.class; break;
     			case ValueMetaInterface.TYPE_BOOLEAN   : parameterType = Boolean.class; break;
     			case ValueMetaInterface.TYPE_BINARY    : parameterType = byte[].class; break;
     			default: parameterType = String.class; break;
     			}
					parameterTypes.add(parameterType);
        			parameterNames.add(valueMeta.getName());
    			}        		
            }        
    	
  	// Create the expression evaluator: is relatively slow so we do it only for the first row...
            //
            data.expressionEvaluator = new ExpressionEvaluator();
            data.expressionEvaluator.setParameters(parameterNames.toArray(new String[parameterNames.size()]), parameterTypes.toArray(new Class<?>[parameterTypes.size()]));
            data.expressionEvaluator.setReturnType(Object.class);
            data.expressionEvaluator.setThrownExceptions(new Class[] { Exception.class });
            data.expressionEvaluator.cook(meta.getCondition());

            // Also create the argument data structure once...
            //
            data.argumentData = new Object[data.argumentIndexes.size()];
    	}
    	
        // This method can only accept the specified number of values...
        //
        for (int x=0;x<data.argumentIndexes.size();x++) {
        	int index = data.argumentIndexes.get(x);
        	ValueMetaInterface outputValueMeta = data.outputRowMeta.getValueMeta(index);
        	data.argumentData[x] = outputValueMeta.convertToNormalStorageType(r[index]);
        }
        
        Object formulaResult  = data.expressionEvaluator.evaluate(data.argumentData);

        if (formulaResult instanceof Boolean) {
        	return (Boolean)formulaResult;
        } else {
        	throw new KettleException("The result of the filter expression must be a boolean and we got back : "+formulaResult.getClass().getName());
        }
    }
    catch(Exception e)
    {
        throw new KettleValueException(e);
    }
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:74,代码来源:JavaFilter.java


注:本文中的org.codehaus.janino.ExpressionEvaluator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。