Class JELArrayFunction<I,O>

java.lang.Object
uk.ac.starlink.ttools.jel.JELArrayFunction<I,O>

public class JELArrayFunction<I,O> extends Object
Provides an array->array function in which input elements are mapped to output elements by use of a given JEL expression.

Instances of this class are not threadsafe.

Since:
23 Mar 2021
Author:
Mark Taylor
  • Constructor Details

    • JELArrayFunction

      public JELArrayFunction(String ivarName, String xvarName, String fexpr, Class<I> inClazz, Class<O> outClazz) throws gnu.jel.CompilationException
      Constructor.
      Parameters:
      ivarName - name of the array index variable (0-based)
      xvarName - name of the array element variable (for instance "x")
      fexpr - text of expression giving the function value, in terms of xvarname (for instance "x+1")
      inClazz - type of input array; must be an array type of primitive or object elements
      outClazz - type of output array; if not known, Object.class may be given, and the output type will be determined from the expression
      Throws:
      gnu.jel.CompilationException
  • Method Details

    • evaluate

      public O evaluate(I inArray)
      Evaluates this expression. Elements for which the evaluation failed are given some type-dependent default value, such as NaN, null, or zero.
      Parameters:
      inArray - input array
      Returns:
      outArray output array, same length as input
    • evaluate

      public static <I> Object evaluate(String ivarName, String xvarName, String fexpr, I inArray) throws gnu.jel.CompilationException
      Utility method to create and use an array function in one go.
      Parameters:
      ivarName - name of the array index variable (for instance "i")
      xvarName - name of the array element variable (for instance "x")
      fexpr - text of expression giving the function value, in terms of xvarname (for instance "x+1")
      inArray - input array
      Returns:
      output array, same length as input
      Throws:
      gnu.jel.CompilationException