Package com.googlecode.aviator
Class AviatorEvaluator
java.lang.Object
com.googlecode.aviator.AviatorEvaluator
Avaitor Expression evaluator
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic int
Deprecated.static final int
Optimized for compile speedstatic final int
Optimized for execute speed,this is the default optionDeprecated.please use instance's field.static final Map
<OperatorType, AviatorFunction> Deprecated.please use instance's field.static final String
Aviator version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addFunction
(AviatorFunction function) Add an aviator function,it's not thread-safe.static void
addFunctionLoader
(FunctionLoader loader) Adds a function loader.addInstanceFunctions
(String namespace, Class<?> clazz) static void
addOpFunction
(OperatorType opType, AviatorFunction function) Add an operator aviator function,it's not thread-safe.addStaticFunctions
(String namespace, Class<?> clazz) static void
Clear all cached compiled expressionstatic Expression
Compile a text expression to Expression Object without cachingstatic Expression
Compile a text expression to Expression objectstatic Expression
Compile a text expression to Expression object and cache it with the specified cache keystatic boolean
containsFunction
(String name) Check if the function exists in the global evaluator instance.static void
defineFunction
(String name, String expression) Define a function by name and expression.static void
Define a function by name and expression with the execution env.static Object
Deprecated.static Object
Execute a text expression without caching and env map.static Object
Execute a text expression with environmentstatic Object
Execute a text expression without cachingstatic Object
Execute a text expression with environmentstatic AviatorClassLoader
Returns classloaderstatic AviatorClassLoader
getAviatorClassLoader
(boolean cached) Returns classloaderstatic Expression
getCachedExpression
(String expression) Returns a compiled expression in cachestatic AviatorFunction
getFunction
(String name) Retrieve an aviator function by name,throw exception if not found or null.It's not thread-safe.static FunctionMissing
static AviatorEvaluatorInstance
Get the default evaluator instancestatic MathContext
Deprecated.Please usegetOption(Options)
static AviatorFunction
getOpFunction
(OperatorType opType) Retrieve an operator aviator function by op type, return null if not found.It's not thread-safe.static <T> T
Deprecated.static Options.Value
getOptionValue
(Options opt) Returns the current evaluator option value union, returns null if missing.static OutputStream
Get current trace output stream,default is System.outimportFunctions
(Class<?> clazz) static void
invalidateCache
(String expression) Invalidate expression cacheA helper method to generate a env object.static AviatorEvaluatorInstance
Create a aviator script engine instance.static AviatorEvaluatorInstance
newInstance
(EvalMode evalMode) Create a aviator script engine instance with eval modestatic AviatorFunction
removeFunction
(AviatorFunction function) Remove a aviator functionstatic AviatorFunction
removeFunction
(String name) Remove an aviator function by name,it's not thread-safe.static void
removeFunctionLoader
(FunctionLoader loader) Removes a function loader.static AviatorFunction
removeOpFunction
(OperatorType opType) Remove an operator aviator function by op type, it's not thread-safe.static void
setAviatorClassLoader
(AviatorClassLoader aviatorClassLoader) Deprecated.static void
setBYTECODE_VER
(int nversion) static void
setFunctionMissing
(FunctionMissing functionMissing) static void
setMathContext
(MathContext mathContext) Deprecated.please usesetOption(Options, Object)
static void
setOptimize
(int value) Deprecated.please usesetOption(Options, Object)
static void
Adds a evaluator optionstatic void
setTraceOutputStream
(OutputStream traceOutputStream) Set trace output streamstatic void
-
Field Details
-
COMPILE
public static final int COMPILEOptimized for compile speed- See Also:
-
EVAL
public static final int EVALOptimized for execute speed,this is the default option- See Also:
-
VERSION
Aviator version -
FUNC_MAP
Deprecated.please use instance's field.The global evaluator's functions map.- See Also:
-
OPS_MAP
Deprecated.please use instance's field.The global evaluator's operators map.- See Also:
-
BYTECODE_VER
Deprecated.The global evaluator's byte code version.- See Also:
-
-
Constructor Details
-
AviatorEvaluator
private AviatorEvaluator()
-
-
Method Details
-
newInstance
Create a aviator script engine instance with eval mode- Returns:
- the script engine
- Since:
- 5.3
-
newInstance
Create a aviator script engine instance.- Returns:
- the script engine
-
getInstance
Get the default evaluator instance- Returns:
- Since:
- 4.0.0
-
newEnv
A helper method to generate a env object. The arguments should be a sequence of pair invalid input: '<'String, Object>.- Parameters:
args
-- Returns:
- A new env instance contains arguments.
- Since:
- 4.2.9
-
addFunctionLoader
Adds a function loader.- Parameters:
loader
-- Since:
- 4.0.0
- See Also:
-
removeFunctionLoader
Removes a function loader.- Parameters:
loader
-- Since:
- 4.0.0
- See Also:
-
setFunctionMissing
- Parameters:
functionMissing
-- See Also:
-
getFunctionMissing
- Parameters:
functionMissing
-- See Also:
-
setOption
Adds a evaluator option- Parameters:
opt
-val
-- Since:
- 2.3.4
- See Also:
-
getOption
Deprecated.Returns the current evaluator option value, returns null if missing. usegetOptionValue(Options)
instead.- Parameters:
opt
-- Returns:
-
getOptionValue
Returns the current evaluator option value union, returns null if missing.- Parameters:
opt
-- Returns:
- the option value, null if missing.
-
getTraceOutputStream
Get current trace output stream,default is System.out- Returns:
-
getMathContext
Deprecated.Please usegetOption(Options)
Returns current math context for decimal.- Returns:
- Since:
- 2.3.0
-
setMathContext
Deprecated.please usesetOption(Options, Object)
Set math context for decimal.- Parameters:
mathContext
-- Since:
- 2.3.0
-
setTraceOutputStream
Set trace output stream- Parameters:
traceOutputStream
-
-
setOptimize
Deprecated.please usesetOption(Options, Object)
set optimize level,default AviatorEvaluator.EVAL- Parameters:
value
-- See Also:
-
setBYTECODE_VER
public static void setBYTECODE_VER(int nversion) -
clearExpressionCache
public static void clearExpressionCache()Clear all cached compiled expression -
getAviatorClassLoader
Returns classloader- Returns:
-
getAviatorClassLoader
Returns classloader- Returns:
-
addInstanceFunctions
public static List<String> addInstanceFunctions(String namespace, Class<?> clazz) throws IllegalAccessException, NoSuchMethodException - Throws:
IllegalAccessException
NoSuchMethodException
- See Also:
-
addStaticFunctions
public static List<String> addStaticFunctions(String namespace, Class<?> clazz) throws IllegalAccessException, NoSuchMethodException - Throws:
IllegalAccessException
NoSuchMethodException
- See Also:
-
importFunctions
public static List<String> importFunctions(Class<?> clazz) throws IllegalAccessException, NoSuchMethodException - Throws:
IllegalAccessException
NoSuchMethodException
- See Also:
-
addFunction
Add an aviator function,it's not thread-safe.- Parameters:
function
-
-
defineFunction
Define a function by name and expression.- Parameters:
name
- the function nameexpression
- the expression to be executed and it's result must be a function.- Since:
- 4.0.0
-
defineFunction
Define a function by name and expression with the execution env.- Parameters:
name
- the function nameexpression
- the expression to be executed and it's result must be a function.env
- the expression execution env- Since:
- 4.0.0
-
removeFunction
Remove an aviator function by name,it's not thread-safe.- Parameters:
name
-- Returns:
-
getFunction
Retrieve an aviator function by name,throw exception if not found or null.It's not thread-safe.- Parameters:
name
-- Returns:
-
addOpFunction
Add an operator aviator function,it's not thread-safe.- Parameters:
function
-
-
getOpFunction
Retrieve an operator aviator function by op type, return null if not found.It's not thread-safe.- Parameters:
opType
-- Returns:
- Since:
- 3.3
-
removeOpFunction
Remove an operator aviator function by op type, it's not thread-safe.- Parameters:
opType
-- Returns:
- Since:
- 3.3
-
containsFunction
Check if the function exists in the global evaluator instance.- Parameters:
name
-- Returns:
-
removeFunction
Remove a aviator function- Parameters:
function
-- Returns:
-
setAviatorClassLoader
Deprecated.Configure user defined classloader- Parameters:
aviatorClassLoader
-
-
getCachedExpression
Returns a compiled expression in cache- Parameters:
expression
-- Returns:
-
compile
Compile a text expression to Expression object and cache it with the specified cache key- Parameters:
cacheKey
- cache keyexpression
- text expressioncached
- Whether to cache the compiled result,make true to cache it.- Returns:
-
compile
Compile a text expression to Expression object- Parameters:
expression
- text expressioncached
- Whether to cache the compiled result,make true to cache it.- Returns:
-
compile
Compile a text expression to Expression Object without caching- Parameters:
expression
-- Returns:
-
validate
- Parameters:
script
-- See Also:
-
exec
Deprecated.Execute a text expression with values that are variables order in the expression.It only runs in EVAL mode,and it will cache the compiled expression. It's deprecated, please useexecute(String, Map)
instead.- Parameters:
expression
-values
-- Returns:
-
execute
public static Object execute(String cacheKey, String expression, Map<String, Object> env, boolean cached) Execute a text expression with environment- Parameters:
cacheKey
- unique key for cachingexpression
- text expressionenv
- Binding variable environmentcached
- Whether to cache the compiled result,make true to cache it.
-
execute
Execute a text expression with environment- Parameters:
expression
- text expressionenv
- Binding variable environmentcached
- Whether to cache the compiled result,make true to cache it.
-
execute
Execute a text expression without caching- Parameters:
expression
-env
-- Returns:
-
invalidateCache
Invalidate expression cache- Parameters:
expression
-
-
execute
Execute a text expression without caching and env map.- Parameters:
expression
-- Returns:
-