Class AviatorEvaluator

java.lang.Object
com.googlecode.aviator.AviatorEvaluator

public final class AviatorEvaluator extends Object
Avaitor Expression evaluator
  • Field Details

  • Constructor Details

    • AviatorEvaluator

      private AviatorEvaluator()
  • Method Details

    • newInstance

      public static AviatorEvaluatorInstance newInstance(EvalMode evalMode)
      Create a aviator script engine instance with eval mode
      Returns:
      the script engine
      Since:
      5.3
    • newInstance

      public static AviatorEvaluatorInstance newInstance()
      Create a aviator script engine instance.
      Returns:
      the script engine
    • getInstance

      public static AviatorEvaluatorInstance getInstance()
      Get the default evaluator instance
      Returns:
      Since:
      4.0.0
    • newEnv

      public static Map<String,Object> newEnv(Object... args)
      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

      public static void addFunctionLoader(FunctionLoader loader)
      Adds a function loader.
      Parameters:
      loader -
      Since:
      4.0.0
      See Also:
    • removeFunctionLoader

      public static void removeFunctionLoader(FunctionLoader loader)
      Removes a function loader.
      Parameters:
      loader -
      Since:
      4.0.0
      See Also:
    • setFunctionMissing

      public static void setFunctionMissing(FunctionMissing functionMissing)
      Parameters:
      functionMissing -
      See Also:
    • getFunctionMissing

      public static FunctionMissing getFunctionMissing()
      Parameters:
      functionMissing -
      See Also:
      • invalid reference
        AviatorEvaluatorInstance#getFunctionMissing(FunctionMissing)
    • setOption

      public static void setOption(Options opt, Object val)
      Adds a evaluator option
      Parameters:
      opt -
      val -
      Since:
      2.3.4
      See Also:
    • getOption

      @Deprecated public static <T> T getOption(Options opt)
      Deprecated.
      Returns the current evaluator option value, returns null if missing. use getOptionValue(Options) instead.
      Parameters:
      opt -
      Returns:
    • getOptionValue

      public static Options.Value getOptionValue(Options opt)
      Returns the current evaluator option value union, returns null if missing.
      Parameters:
      opt -
      Returns:
      the option value, null if missing.
    • getTraceOutputStream

      public static OutputStream getTraceOutputStream()
      Get current trace output stream,default is System.out
      Returns:
    • getMathContext

      @Deprecated public static MathContext getMathContext()
      Deprecated.
      Returns current math context for decimal.
      Returns:
      Since:
      2.3.0
    • setMathContext

      @Deprecated public static void setMathContext(MathContext mathContext)
      Deprecated.
      Set math context for decimal.
      Parameters:
      mathContext -
      Since:
      2.3.0
    • setTraceOutputStream

      public static void setTraceOutputStream(OutputStream traceOutputStream)
      Set trace output stream
      Parameters:
      traceOutputStream -
    • setOptimize

      @Deprecated public static void setOptimize(int value)
      Deprecated.
      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

      public static AviatorClassLoader getAviatorClassLoader()
      Returns classloader
      Returns:
    • getAviatorClassLoader

      public static AviatorClassLoader getAviatorClassLoader(boolean cached)
      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

      public static void addFunction(AviatorFunction function)
      Add an aviator function,it's not thread-safe.
      Parameters:
      function -
    • defineFunction

      public static void defineFunction(String name, String expression)
      Define a function by name and expression.
      Parameters:
      name - the function name
      expression - the expression to be executed and it's result must be a function.
      Since:
      4.0.0
    • defineFunction

      public static void defineFunction(String name, String expression, Map<String,Object> env)
      Define a function by name and expression with the execution env.
      Parameters:
      name - the function name
      expression - the expression to be executed and it's result must be a function.
      env - the expression execution env
      Since:
      4.0.0
    • removeFunction

      public static AviatorFunction removeFunction(String name)
      Remove an aviator function by name,it's not thread-safe.
      Parameters:
      name -
      Returns:
    • getFunction

      public static AviatorFunction getFunction(String name)
      Retrieve an aviator function by name,throw exception if not found or null.It's not thread-safe.
      Parameters:
      name -
      Returns:
    • addOpFunction

      public static void addOpFunction(OperatorType opType, AviatorFunction function)
      Add an operator aviator function,it's not thread-safe.
      Parameters:
      function -
    • getOpFunction

      public static AviatorFunction getOpFunction(OperatorType opType)
      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

      public static AviatorFunction removeOpFunction(OperatorType opType)
      Remove an operator aviator function by op type, it's not thread-safe.
      Parameters:
      opType -
      Returns:
      Since:
      3.3
    • containsFunction

      public static boolean containsFunction(String name)
      Check if the function exists in the global evaluator instance.
      Parameters:
      name -
      Returns:
    • removeFunction

      public static AviatorFunction removeFunction(AviatorFunction function)
      Remove a aviator function
      Parameters:
      function -
      Returns:
    • setAviatorClassLoader

      @Deprecated public static void setAviatorClassLoader(AviatorClassLoader aviatorClassLoader)
      Deprecated.
      Configure user defined classloader
      Parameters:
      aviatorClassLoader -
    • getCachedExpression

      public static Expression getCachedExpression(String expression)
      Returns a compiled expression in cache
      Parameters:
      expression -
      Returns:
    • compile

      public static Expression compile(String cacheKey, String expression, boolean cached)
      Compile a text expression to Expression object and cache it with the specified cache key
      Parameters:
      cacheKey - cache key
      expression - text expression
      cached - Whether to cache the compiled result,make true to cache it.
      Returns:
    • compile

      public static Expression compile(String expression, boolean cached)
      Compile a text expression to Expression object
      Parameters:
      expression - text expression
      cached - Whether to cache the compiled result,make true to cache it.
      Returns:
    • compile

      public static Expression compile(String expression)
      Compile a text expression to Expression Object without caching
      Parameters:
      expression -
      Returns:
    • validate

      public static void validate(String script)
      Parameters:
      script -
      See Also:
    • exec

      @Deprecated public static Object exec(String expression, Object... values)
      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 use execute(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 caching
      expression - text expression
      env - Binding variable environment
      cached - Whether to cache the compiled result,make true to cache it.
    • execute

      public static Object execute(String expression, Map<String,Object> env, boolean cached)
      Execute a text expression with environment
      Parameters:
      expression - text expression
      env - Binding variable environment
      cached - Whether to cache the compiled result,make true to cache it.
    • execute

      public static Object execute(String expression, Map<String,Object> env)
      Execute a text expression without caching
      Parameters:
      expression -
      env -
      Returns:
    • invalidateCache

      public static void invalidateCache(String expression)
      Invalidate expression cache
      Parameters:
      expression -
    • execute

      public static Object execute(String expression)
      Execute a text expression without caching and env map.
      Parameters:
      expression -
      Returns: