Package com.singularsys.jep.misc.functions

# Class ElementOf

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.ArrayFunctionBase
com.singularsys.jep.misc.functions.ElementOf

All Implemented Interfaces:
  `ZeroLengthBehaviourI`, `PostfixMathCommandI`, `Serializable`

public class ElementOf extends ArrayFunctionBase
Tests if the first argument is in a set of values given in subsequent arguments. For example IN(var,"north","south","east","west"). An array can be used for a two argument version IN(var,["north","south","east","west"]). The function can be configured to return the negation, i.e. not element of.

The function could be used as an operator:

     public enum InOperators implements EmptyOperatorTable.OperatorKey {
          IN,NOTIN
     }

     Jep jep = new Jep(new StandardConfigurableParser());
     OperatorTableI opTab = jep.getOperatorTable();
     Operator eqOp = opTab.getEQ();
     Operator inOp = new Operator(
       "IN",
       new ElementOf((Comparative) eqOp.getPFMC(),true),
       Operator.BINARY+Operator.RIGHT);
     Operator notInOp = new Operator(
       "NOTIN",
       new ElementOf((Comparative) eqOp.getPFMC(),false),
       Operator.BINARY+Operator.RIGHT);
     opTab.addOperator(InOperators.IN,inOp,eqOp);
     opTab.addOperator(InOperators.NOTIN,notInOp,eqOp);
     jep.reinitializeComponents();

Since:
  3.5.0
Author:
  Richard Morris
See Also:
  - Serialized Form

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI

  `ZeroLengthBehaviourI.DefaultZeroLengthBehaviourI, ZeroLengthBehaviourI.ZeroLengthErrorBehaviour, ZeroLengthBehaviourI.ZeroLengthHelper`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final Comparative`
  `comp`

  ### Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ElementOf(Comparative comp, boolean elementOf)`
  Construct the function.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected Object`
  `calc(Object first, List<Object> l)`
  Calculates if the element is in the list or not.
  `protected Object`
  `calc(List<Object> l)`
  Should not be called.
  `void`
  `run(Stack<Object> stack)`
  Calls the calc method after concatenating the second and subsequent elements into list.

  ### Methods inherited from class com.singularsys.jep.functions.ArrayFunctionBase

  `addToArray, checkNumberOfParameters, getZeroLengthErrorBehaviour, getZeroLengthValue, setZeroLengthErrorBehaviour, setZeroLengthValue, throwAtLeastOneExcep`

  ### Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, getDescription, getDescription, getDescriptionWithType, getName, getNumberOfParameters, setCurNumberOfParameters, setDescription, setName, toString, toString`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface com.singularsys.jep.functions.ZeroLengthBehaviourI

  `getErrorMessage, getValueOrException, zeroLengthResultOrException`

- ## Field Details

  - ### comp

    protected final Comparative comp

- ## Constructor Details

  - ### ElementOf

    public ElementOf(Comparative comp, boolean elementOf)
    Construct the function.
    Parameters:
      `comp` - comparative object used to compare two elements
      `elementOf` - whether the function calculate "element-of" or "not element-of". If false the result of function is negated.

- ## Method Details

  - ### calc

    protected Object calc(Object first, List<Object> l) throws EvaluationException
    Calculates if the element is in the list or not.
    Parameters:
      `first` - element to test
      `l` - list with all the other arguments in the list
    Returns:
      `Boolean.TRUE` or `Boolean.FALSE` depending on if the element is in the list.
    Throws:
      `EvaluationException`

  - ### run

    public void run(Stack<Object> stack) throws EvaluationException
    Calls the calc method after concatenating the second and subsequent elements into list.
    Specified by:
      `run` in interface `PostfixMathCommandI`
    Overrides:
      `run` in class `ArrayFunctionBase`
    Parameters:
      `stack` - arguments for function
    Throws:
      `EvaluationException` - if function cannot be evaluated

  - ### calc

    protected Object calc(List<Object> l) throws EvaluationException
    Should not be called.
    Specified by:
      `calc` in class `ArrayFunctionBase`
    Parameters:
      `l` - The list to operate on. Note this is in reverse order of the arguments of the function.
    Returns:
      The result of the calculation.
    Throws:
      `EvaluationException` - always