Interface Evaluator<T>

  • Type Parameters:
    T - The return type that is needed by the caller
    All Known Implementing Classes:
    NashornEvaluator

    public interface Evaluator<T>

    An evaluator is a scripting helper that knows what its return type will be at runtime. You can create an Evaluator from an environment and a desired return type, then reuse it. Primitive types that can be mapped from the script to the return type should, including

    • Double -> Long
    • Double -> Integer
    • Double -> Float
    • Long -> Integer

    An evaluator is not threadsafe by default. If you need threadsafe evaluators with similar semantics, wrap it in a ThreadLocal.

    • Method Summary

      Modifier and Type Method Description
      T eval()
      Evaluate the provided script, returning the value that it yields
      NashornEvaluator<T> put​(java.lang.String varName, java.lang.Object var)
      Set the variable environment of the evaluator
      NashornEvaluator<T> script​(java.lang.String scriptText)  
    • Method Detail

      • eval

        T eval()
        Evaluate the provided script, returning the value that it yields
        Returns:
        An object of type T
      • script

        NashornEvaluator<T> script​(java.lang.String scriptText)
        Parameters:
        scriptText - Nashorn compatible script text
        Returns:
        this NahornEvaluator, for method chaining
      • put

        NashornEvaluator<T> put​(java.lang.String varName,
                                java.lang.Object var)
        Set the variable environment of the evaluator
        Parameters:
        varName - the variable name to add to the environment
        var - the object to bind to the varname
        Returns:
        this NashornEvaluator, for method chaining