Class StreamExternalMap

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class StreamExternalMap extends UnaryFunction implements JepComponent
Applies an externally defined mapping function to each element of a stream. The mapping function can be provided either as a Function or as a UnaryFunction that takes one argument and returns the mapped value.
jep.addFunction("toInt",
    new ChainableUnaryFunction(
        new StreamExternalMap(
            UnaryFunction.instanceOf(
                Number.class, x -> ((Number) x).intValue()))));
See Also:
  • Constructor Details

    • StreamExternalMap

      public StreamExternalMap(Function<Object,Object> map)
      Constructor using a Function.
      Parameters:
      map - the mapping function to apply to each element of the stream
    • StreamExternalMap

      public StreamExternalMap(UnaryFunction fun)
      Constructor using a UnaryFunction.
      Parameters:
      fun - a function that takes one argument and returns the mapped value.
  • Method Details

    • eval

      public Object eval(Object arg) throws EvaluationException
      Description copied from class: UnaryFunction
      Evaluate the function
      Specified by:
      eval in class UnaryFunction
      Parameters:
      arg - the single argument passed in
      Returns:
      the result of the function
      Throws:
      EvaluationException - on error
    • init

      public void init(Jep jep)
      Description copied from interface: JepComponent
      Initialize the component. This method is called whenever a component is added to Jep. Hence, it allows components to keep track of the other components they may rely on.
      Specified by:
      init in interface JepComponent
      Parameters:
      jep - the current Jep instance
    • getLightWeightInstance

      public JepComponent getLightWeightInstance()
      Description copied from interface: JepComponent
      Gets a light-weight instance suitable for using in multiple threads.
      Specified by:
      getLightWeightInstance in interface JepComponent
      Returns:
      either a new instance, null or 'this'.