Class DataScriptHelper


  • public final class DataScriptHelper
    extends Object
    This DataScriptHelper class can be used to effectively use the GroovyShell to evaluate dynamic groovy expressions.

    The DataScriptHelper maintains an internal LRU cache to reuse the parsed script. If the specified expiry time is elapsed without any access to the cached script, the cache is evicted to regain the memory.
    • Constructor Detail

      • DataScriptHelper

        public DataScriptHelper​(int cacheSize,
                                int expireTime,
                                boolean indy)
        Create a new DataScriptHelper with the given cacheSize and expireTime in minutes.
        Parameters:
        cacheSize - Size of the cache.
        expireTime - The expire time in minutes after which the script is evicted from the cache if not accessed.
        indy - Whether to use the invoke dynamic feature.
    • Method Detail

      • eval

        public Object eval​(String expression,
                           Map<String,​Object> variables)
        Evaluate the given expression.

        An instance of Binding is created to deal with missing variables. In that case, null is returned and avoids MissingPropertyException.
        Parameters:
        expression - the groovy expression to evaluate
        variables - the binding variables
        Returns:
        the result of the expression
      • eval

        public Object eval​(String expression,
                           groovy.lang.Binding binding)
        Evaluate the given expression.
        Parameters:
        expression - the groovy expression to evaluate
        binding - the binding variables
        Returns:
        the result of the expression