Class StreamExternalFilter

All Implemented Interfaces:
JepComponent, PostfixMathCommandI, Serializable

public class StreamExternalFilter extends UnaryFunction implements JepComponent
Filters elements of a stream based on a externally defined predicate. The predicate can be provided either as a Predicate or as a UnaryFunction that returns a boolean value.

For example, to filter out NaN values from a stream of numbers, you could define a function like this:

jep.addFunction("nanfilter",
   new ChainableUnaryFunction(
      new StreamExternalFilter(
          x-> !Double.isNaN(((Number) x).doubleValue()))));
See Also:
  • Constructor Details

    • StreamExternalFilter

      public StreamExternalFilter(Predicate<Object> filter)
      Constructor using a predicate.
      Parameters:
      filter - the predicate used to filter elements
    • StreamExternalFilter

      public StreamExternalFilter(UnaryFunction fun)
      Constructor using a unary function.
      Parameters:
      fun - a function that returns a boolean 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'.