Package groovy.util
Class Eval
- java.lang.Object
- 
- groovy.util.Eval
 
- 
 public class Eval extends Object Allow easy integration from Groovy into Java through convenience methods.This class is a simple helper on top of GroovyShell. You can use it to evaluate small Groovy scripts that don't need large Binding objects. For example, this script executes with no errors: assert Eval.me(' 2 * 4 + 2') == 10 assert Eval.x(2, ' x * 4 + 2') == 10- See Also:
- GroovyShell
 
- 
- 
Constructor SummaryConstructors Constructor Description Eval()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static Objectme(String expression)Evaluates the specified String expression and returns the result.static Objectme(String symbol, Object object, String expression)Evaluates the specified String expression and makes the parameter available inside the script, returning the result.static Objectx(Object x, String expression)Evaluates the specified String expression and makes the parameter available inside the script bound to a variable named 'x', returning the result.static Objectxy(Object x, Object y, String expression)Evaluates the specified String expression and makes the first two parameters available inside the script bound to variables named 'x' and 'y' respectively, returning the result.static Objectxyz(Object x, Object y, Object z, String expression)Evaluates the specified String expression and makes the first three parameters available inside the script bound to variables named 'x', 'y', and 'z' respectively, returning the result.
 
- 
- 
- 
Method Detail- 
mepublic static Object me(String expression) throws CompilationFailedException Evaluates the specified String expression and returns the result. For example:assert Eval.me(' 2 * 4 + 2') == 10- Parameters:
- expression- the Groovy expression to evaluate
- Returns:
- the result of the expression
- Throws:
- CompilationFailedException- if expression is not valid Groovy
 
 - 
mepublic static Object me(String symbol, Object object, String expression) throws CompilationFailedException Evaluates the specified String expression and makes the parameter available inside the script, returning the result. For example, this code binds the 'x' variable:assert Eval.me('x', 2, ' x * 4 + 2') == 10- Parameters:
- expression- the Groovy expression to evaluate
- Returns:
- the result of the expression
- Throws:
- CompilationFailedException- if expression is not valid Groovy
 
 - 
xpublic static Object x(Object x, String expression) throws CompilationFailedException Evaluates the specified String expression and makes the parameter available inside the script bound to a variable named 'x', returning the result. For example, this code executes without failure:assert Eval.x(2, ' x * 4 + 2') == 10 - Parameters:
- expression- the Groovy expression to evaluate
- Returns:
- the result of the expression
- Throws:
- CompilationFailedException- if expression is not valid Groovy
 
 - 
xypublic static Object xy(Object x, Object y, String expression) throws CompilationFailedException Evaluates the specified String expression and makes the first two parameters available inside the script bound to variables named 'x' and 'y' respectively, returning the result. For example, this code executes without failure:assert Eval.xy(2, 4, ' x * y + 2') == 10 - Parameters:
- expression- the Groovy expression to evaluate
- Returns:
- the result of the expression
- Throws:
- CompilationFailedException- if expression is not valid Groovy
 
 - 
xyzpublic static Object xyz(Object x, Object y, Object z, String expression) throws CompilationFailedException Evaluates the specified String expression and makes the first three parameters available inside the script bound to variables named 'x', 'y', and 'z' respectively, returning the result. For example, this code executes without failure:assert Eval.xyz(2, 4, 2, ' x * y + z') == 10 - Parameters:
- expression- the Groovy expression to evaluate
- Returns:
- the result of the expression
- Throws:
- CompilationFailedException- if expression is not valid Groovy
 
 
- 
 
-