Class AviatorEvaluator


  • public final class AviatorEvaluator
    extends java.lang.Object
    Avaitor Expression evaluator
    • Constructor Detail

      • AviatorEvaluator

        private AviatorEvaluator()
    • Method Detail

      • 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 java.util.Map<java.lang.String,​java.lang.Object> newEnv​(java.lang.Object... args)
        A helper method to generate a env object. The arguments should be a sequence of pair .
        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:
        FunctionLoader
      • removeFunctionLoader

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

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

        public static void setOption​(Options opt,
                                     java.lang.Object val)
        Adds a evaluator option
        Parameters:
        opt -
        val -
        Since:
        2.3.4
        See Also:
        Options
      • 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 java.io.OutputStream getTraceOutputStream()
        Get current trace output stream,default is System.out
        Returns:
      • getMathContext

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

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

        public static void setTraceOutputStream​(java.io.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:
        COMPILE, EVAL
      • 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 java.util.List<java.lang.String> addInstanceFunctions​(java.lang.String namespace,
                                                                            java.lang.Class<?> clazz)
                                                                     throws java.lang.IllegalAccessException,
                                                                            java.lang.NoSuchMethodException
        Throws:
        java.lang.IllegalAccessException
        java.lang.NoSuchMethodException
        See Also:
        AviatorEvaluatorInstance.addInstanceFunctions(String, Class)
      • addStaticFunctions

        public static java.util.List<java.lang.String> addStaticFunctions​(java.lang.String namespace,
                                                                          java.lang.Class<?> clazz)
                                                                   throws java.lang.IllegalAccessException,
                                                                          java.lang.NoSuchMethodException
        Throws:
        java.lang.IllegalAccessException
        java.lang.NoSuchMethodException
        See Also:
        AviatorEvaluatorInstance.addStaticFunctions(String, Class)
      • importFunctions

        public static java.util.List<java.lang.String> importFunctions​(java.lang.Class<?> clazz)
                                                                throws java.lang.IllegalAccessException,
                                                                       java.lang.NoSuchMethodException
        Throws:
        java.lang.IllegalAccessException
        java.lang.NoSuchMethodException
        See Also:
        AviatorEvaluatorInstance.importFunctions(Class)
      • addFunction

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

        public static void defineFunction​(java.lang.String name,
                                          java.lang.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​(java.lang.String name,
                                          java.lang.String expression,
                                          java.util.Map<java.lang.String,​java.lang.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​(java.lang.String name)
        Remove an aviator function by name,it's not thread-safe.
        Parameters:
        name -
        Returns:
      • getFunction

        public static AviatorFunction getFunction​(java.lang.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​(java.lang.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​(java.lang.String expression)
        Returns a compiled expression in cache
        Parameters:
        expression -
        Returns:
      • compile

        public static Expression compile​(java.lang.String cacheKey,
                                         java.lang.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​(java.lang.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​(java.lang.String expression)
        Compile a text expression to Expression Object without caching
        Parameters:
        expression -
        Returns:
      • exec

        @Deprecated
        public static java.lang.Object exec​(java.lang.String expression,
                                            java.lang.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 java.lang.Object execute​(java.lang.String cacheKey,
                                               java.lang.String expression,
                                               java.util.Map<java.lang.String,​java.lang.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 java.lang.Object execute​(java.lang.String expression,
                                               java.util.Map<java.lang.String,​java.lang.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 java.lang.Object execute​(java.lang.String expression,
                                               java.util.Map<java.lang.String,​java.lang.Object> env)
        Execute a text expression without caching
        Parameters:
        expression -
        env -
        Returns:
      • invalidateCache

        public static void invalidateCache​(java.lang.String expression)
        Invalidate expression cache
        Parameters:
        expression -
      • execute

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