View Javadoc
1   /*******************************************************************************
2    * Portions created by Sebastian Thomschke are copyright (c) 2005-2015 Sebastian
3    * Thomschke.
4    *
5    * All Rights Reserved. This program and the accompanying materials
6    * are made available under the terms of the Eclipse Public License v1.0
7    * which accompanies this distribution, and is available at
8    * http://www.eclipse.org/legal/epl-v10.html
9    *
10   * Contributors:
11   *     Sebastian Thomschke - initial implementation.
12   *******************************************************************************/
13  package net.sf.oval.expression;
14  
15  import java.util.Map;
16  
17  import net.sf.oval.exception.ExpressionEvaluationException;
18  
19  /**
20   * @author Sebastian Thomschke
21   */
22  public interface ExpressionLanguage
23  {
24  	/**
25  	 * Evaluates the given expression.
26  	 * 
27  	 * @param expression the expression to evaluate
28  	 * @param values context values passed to the interpreter
29  	 * @return the result of the expression evaluation
30  	 * @throws ExpressionEvaluationException in case of an invalid expression
31  	 */
32  	Object evaluate(String expression, Map<String, ? > values) throws ExpressionEvaluationException;
33  
34  	/**
35  	 * Evaluates the given expression and expects it to return a boolean.
36  	 * <li><code>null</code> is interpreted as <code>false</code>
37  	 * <li>a number with value 0 is interpreted as <code>false</code>
38  	 * <li>an empty {@link CharSequence} is interpreted as <code>false</code>
39  	 * <li>a {@link CharSequence} with value "0" is interpreted as <code>false</code>
40  	 * <li>a {@link CharSequence} with value "1" is interpreted as <code>true</code>
41  	 * <li>a {@link CharSequence} with value "false" is case-insensitively interpreted as <code>false</code>
42  	 * <li>a {@link CharSequence} with value "true" is case-insensitively interpreted as <code>true</code>
43  	 *
44  	 * @param expression the expression to evaluate
45  	 * @param values context values passed to the interpreter
46  	 * @return the result of the expression evaluation
47  	 * @throws ExpressionEvaluationException If an error during evaluation occurs or if the return value is not a boolean value.
48  	 */
49  	boolean evaluateAsBoolean(String expression, Map<String, ? > values) throws ExpressionEvaluationException;
50  }