Class AviatorEvaluator
java.lang.Object
com.googlecode.aviator.AviatorEvaluator
Avaitor Expression evaluator
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic intDeprecated.static final intOptimized for compile speedstatic final intOptimized 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 StringAviator version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddFunction(AviatorFunction function) Add an aviator function,it's not thread-safe.static voidaddFunctionLoader(FunctionLoader loader) Adds a function loader.addInstanceFunctions(String namespace, Class<?> clazz) static voidaddOpFunction(OperatorType opType, AviatorFunction function) Add an operator aviator function,it's not thread-safe.addStaticFunctions(String namespace, Class<?> clazz) static voidClear all cached compiled expressionstatic ExpressionCompile a text expression to Expression Object without cachingstatic ExpressionCompile a text expression to Expression objectstatic ExpressionCompile a text expression to Expression object and cache it with the specified cache keystatic booleancontainsFunction(String name) Check if the function exists in the global evaluator instance.static voiddefineFunction(String name, String expression) Define a function by name and expression.static voidDefine a function by name and expression with the execution env.static ObjectDeprecated.static ObjectExecute a text expression without caching and env map.static ObjectExecute a text expression with environmentstatic ObjectExecute a text expression without cachingstatic ObjectExecute a text expression with environmentstatic AviatorClassLoaderReturns classloaderstatic AviatorClassLoadergetAviatorClassLoader(boolean cached) Returns classloaderstatic ExpressiongetCachedExpression(String expression) Returns a compiled expression in cachestatic AviatorFunctiongetFunction(String name) Retrieve an aviator function by name,throw exception if not found or null.It's not thread-safe.static FunctionMissingstatic AviatorEvaluatorInstanceGet the default evaluator instancestatic MathContextDeprecated.Please usegetOption(Options)static AviatorFunctiongetOpFunction(OperatorType opType) Retrieve an operator aviator function by op type, return null if not found.It's not thread-safe.static <T> TDeprecated.static Options.ValuegetOptionValue(Options opt) Returns the current evaluator option value union, returns null if missing.static OutputStreamGet current trace output stream,default is System.outimportFunctions(Class<?> clazz) static voidinvalidateCache(String expression) Invalidate expression cacheA helper method to generate a env object.static AviatorEvaluatorInstanceCreate a aviator script engine instance.static AviatorEvaluatorInstancenewInstance(EvalMode evalMode) Create a aviator script engine instance with eval modestatic AviatorFunctionremoveFunction(AviatorFunction function) Remove a aviator functionstatic AviatorFunctionremoveFunction(String name) Remove an aviator function by name,it's not thread-safe.static voidremoveFunctionLoader(FunctionLoader loader) Removes a function loader.static AviatorFunctionremoveOpFunction(OperatorType opType) Remove an operator aviator function by op type, it's not thread-safe.static voidsetAviatorClassLoader(AviatorClassLoader aviatorClassLoader) Deprecated.static voidsetBYTECODE_VER(int nversion) static voidsetFunctionMissing(FunctionMissing functionMissing) static voidsetMathContext(MathContext mathContext) Deprecated.please usesetOption(Options, Object)static voidsetOptimize(int value) Deprecated.please usesetOption(Options, Object)static voidAdds a evaluator optionstatic voidsetTraceOutputStream(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
-
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
-
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
-
getAviatorClassLoader
-
addInstanceFunctions
public static List<String> addInstanceFunctions(String namespace, Class<?> clazz) throws IllegalAccessException, NoSuchMethodException - Throws:
IllegalAccessExceptionNoSuchMethodException- See Also:
-
addStaticFunctions
public static List<String> addStaticFunctions(String namespace, Class<?> clazz) throws IllegalAccessException, NoSuchMethodException - Throws:
IllegalAccessExceptionNoSuchMethodException- See Also:
-
importFunctions
public static List<String> importFunctions(Class<?> clazz) throws IllegalAccessException, NoSuchMethodException - Throws:
IllegalAccessExceptionNoSuchMethodException- See Also:
-
addFunction
Add an aviator function,it's not thread-safe.- Parameters:
function-
-
defineFunction
-
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
-
invalidateCache
Invalidate expression cache- Parameters:
expression-
-
execute
-