|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.util.Eval
public class Eval
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 10 == Eval.me(' 2 * 4 + 2') assert 10 == Eval.x(2, ' x * 4 + 2')
GroovyShell
Constructor Summary | |
---|---|
Eval()
|
Method Summary | |
---|---|
static Object |
me(String expression)
Evaluates the specified String expression and returns the result. |
static Object |
me(String symbol,
Object object,
String expression)
Evaluates the specified String expression and makes the parameter available inside the script, returning the result. |
static Object |
x(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 Object |
xy(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 Object |
xyz(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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Eval()
Method Detail |
---|
public static Object me(String expression) throws CompilationFailedException
assert 10 == Eval.me(' 2 * 4 + 2')
expression
- the Groovy expression to evaluate
CompilationFailedException
- if expression is not valid Groovypublic static Object me(String symbol, Object object, String expression) throws CompilationFailedException
assert 10 == Eval.me('x', 2, ' x * 4 + 2')
expression
- the Groovy expression to evaluate
CompilationFailedException
- if expression is not valid Groovypublic static Object x(Object x, String expression) throws CompilationFailedException
assert 10 == Eval.x(2, ' x * 4 + 2')
expression
- the Groovy expression to evaluate
CompilationFailedException
- if expression is not valid Groovypublic static Object xy(Object x, Object y, String expression) throws CompilationFailedException
assert 10 == Eval.xy(2, 4, ' x * y + 2')
expression
- the Groovy expression to evaluate
CompilationFailedException
- if expression is not valid Groovypublic static Object xyz(Object x, Object y, Object z, String expression) throws CompilationFailedException
assert 10 == Eval.xyz(2, 4, 2, ' x * y + z')
expression
- the Groovy expression to evaluate
CompilationFailedException
- if expression is not valid Groovy
|
Copyright © 2003-2012 The Codehaus. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |