Package com.singularsys.jep.functions

# Class If

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.If

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

Direct Known Subclasses:
  `NullWrappedIf`

public class If extends PostfixMathCommand implements CallbackEvaluationI
The if(condExpr, posExpr, negExpr) function. The value of trueExpr will be returned if condExpr is >0 or `Boolean.TRUE` and value of negExpr will be returned if condExpr is <= 0 or `Boolean.TRUE`. If condExpr is NaN then NaN is returned.

This function performs lazy evaluation so that only posExpr or negExpr will be evaluated. For Complex numbers only the real part is used.

An alternate form if(condExpr, posExpr, negExpr, zeroExpr) is also available. Note most computations are carried out over floating point doubles so testing for zero can be dangerous.

Note most computations are carried out over floating point doubles so testing for zero can be dangerous.

Since:
  Feb 05 Handles Number arguments, so works with Integers rather than just Doubles
Version:
  2.3.0 beta 1 now supports a Boolean first argument.
Author:
  Rich Morris Created on 18-Nov-2003
See Also:
  - Serialized Form

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Object`
  `falseValue`

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

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `If()`
  `If(Object falseValue)`
  If this constructor is used then a two argument version can be used `if(condExpr, posExpr)` is also available.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `checkNumberOfParameters(int n)`
  Checks the number of parameters of the call.
  `Object`
  `evaluate(Node node, Evaluator pv)`
  Performs some special evaluation on the node.
  `Object`
  `getFalseValue()`
  The value returned for false values in the two argument version.

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

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

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

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

- ## Field Details

  - ### falseValue

    protected Object falseValue

- ## Constructor Details

  - ### If

    public If()

  - ### If

    public If(Object falseValue)
    If this constructor is used then a two argument version can be used `if(condExpr, posExpr)` is also available.
    Parameters:
      `falseValue` - the value to return when condExpr is false in the two argument version

- ## Method Details

  - ### checkNumberOfParameters

    public boolean checkNumberOfParameters(int n)
    Checks the number of parameters of the call.
    Specified by:
      `checkNumberOfParameters` in interface `PostfixMathCommandI`
    Overrides:
      `checkNumberOfParameters` in class `PostfixMathCommand`
    Parameters:
      `n` - number of parameters function will be called with.
    Returns:
      false if an illegal number of parameters is supplied, true otherwise.

  - ### evaluate

    public Object evaluate(Node node, Evaluator pv) throws EvaluationException
    Description copied from interface: `CallbackEvaluationI`
    Performs some special evaluation on the node. This method has the responsibility for evaluating the children of the node, and it should generally call

         pv.eval(node.jjtGetChild(i))

    for each child. The SymbolTable is not passed as an argument. This is because it is better practice to get and set variable values by using node.getVar().setValue() rather that through the SymbolTable with requires a hashtable lookup.
    Specified by:
      `evaluate` in interface `CallbackEvaluationI`
    Parameters:
      `node` - The current node
      `pv` - The visitor, can be used evaluate the children
    Returns:
      the value after evaluation. This value will be passed to other functions higher up the node tree. The value can be any type including Double or Vector<Object>
    Throws:
      `EvaluationException` - if the calculation cannot be performed
    See Also:
      - `Evaluator`

  - ### getFalseValue

    public Object getFalseValue()
    The value returned for false values in the two argument version.
    Returns:
      value returned
    Since:
      3.4.0