Package com.singularsys.jep.functions

# Class Comparative

java.lang.Object
com.singularsys.jep.functions.PostfixMathCommand
com.singularsys.jep.functions.BinaryFunction
com.singularsys.jep.functions.Comparative

All Implemented Interfaces:
  `PostfixMathCommandI`, `Serializable`

Direct Known Subclasses:
  `BigDecRelational`, `NullSafeEquals`

public class Comparative extends BinaryFunction
Implements the comparative operations <, >, <=, >=, != and ==. The <, >, <=, >= operators only work on Double type, while the != and == operators also work on String and Vector arguments. For other types, care might be needed.

Complex numbers are compared using a tolerance which can be set using setTolerance().

Since:
  2.3.0 beta 1 a bit of a rewrite to make sub classing easier, now allows Complex to be compared to Double i.e. 1+0 i == 1., 2.3.0 beta 2 changed the internal lt,gt,le,ge,ne and eq method to return boolean. If this breaks anything use if (lt(obj1,obj2)) inStack.push(Double.valueOf(1)); else inStack.push(Double.valueOf(0));, Jep 4.1 `List<Object>` are compared for equality and inequality by comparing their elements pairwise, so vectors with positive zero and negative zero are considered equal,
Author:
  N Funk and R Morris
See Also:
  - Serialized Form

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from class com.singularsys.jep.functions.BinaryFunction

  `BinaryFunction.BiFunctionWithException<T>`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `EQ`
  `static final int`
  `GE`
  `static final int`
  `GT`
  `static final int`
  `LE`
  `static final int`
  `LT`
  `static final int`
  `NE`

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

  `curNumberOfParameters, description, name, NaN, numberOfParameters`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Comparative(int id_in)`
  Constructor.
  `Comparative(int id, double tolerance)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `boolean`
  `compare(Object param1, Object param2)`
  Compares the two arguments.
  `boolean`
  `eq(Object param1, Object param2)`
  `Object`
  `eval(Object l, Object r)`
  Evaluate the function
  `boolean`
  `ge(Object param1, Object param2)`
  `String`
  `getDescription()`
  Return a description of the function from the properties file.
  `int`
  `getId()`
  Return the ID of the comparative operator
  `double`
  `getTolerance()`
  Returns the tolerance used for comparing complex numbers
  `boolean`
  `gt(Object param1, Object param2)`
  `boolean`
  `le(Object param1, Object param2)`
  `boolean`
  `lt(Object param1, Object param2)`
  `boolean`
  `ne(Object param1, Object param2)`
  `void`
  `setTolerance(double d)`
  Sets the tolerance used for comparing complex numbers

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

  `instanceOf, instanceOf, instanceOf, instanceOf, run`

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

  `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, asType, checkNumberOfParameters, 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`

- ## Field Details

  - ### LT

    public static final int LT
    See Also:
      - Constant Field Values

  - ### GT

    public static final int GT
    See Also:
      - Constant Field Values

  - ### LE

    public static final int LE
    See Also:
      - Constant Field Values

  - ### GE

    public static final int GE
    See Also:
      - Constant Field Values

  - ### NE

    public static final int NE
    See Also:
      - Constant Field Values

  - ### EQ

    public static final int EQ
    See Also:
      - Constant Field Values

- ## Constructor Details

  - ### Comparative

    public Comparative(int id_in)
    Constructor. Sets the number of parameters to 2. Initializes the tolerance for comparing Complex values.
    Parameters:
      `id_in` - The id of the comparative operator.

  - ### Comparative

    public Comparative(int id, double tolerance)
    Parameters:
      `id` - one of LT, GT, LE, GE, EQ, NE
      `tolerance` - tolerance for comparing Complex values

- ## Method Details

  - ### getId

    public int getId()
    Return the ID of the comparative operator
    Returns:
      the id code
    Since:
      3.5

  - ### eval

    public Object eval(Object l, Object r) throws EvaluationException
    Description copied from class: `BinaryFunction`
    Evaluate the function
    Specified by:
      `eval` in class `BinaryFunction`
    Parameters:
      `l` - lhs argument
      `r` - rhs argument
    Returns:
      the results
    Throws:
      `EvaluationException` - if the function cannot be evaluated.

  - ### compare

    public boolean compare(Object param1, Object param2) throws EvaluationException
    Compares the two arguments. Result depend on which comparative option has been selected.
    Parameters:
      `param1` -
      `param2` -
    Returns:
    Throws:
      `EvaluationException`

  - ### lt

    public boolean lt(Object param1, Object param2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### gt

    public boolean gt(Object param1, Object param2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### le

    public boolean le(Object param1, Object param2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### ge

    public boolean ge(Object param1, Object param2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### eq

    public boolean eq(Object param1, Object param2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### ne

    public boolean ne(Object param1, Object param2) throws EvaluationException
    Throws:
      `EvaluationException`

  - ### getTolerance

    public double getTolerance()
    Returns the tolerance used for comparing complex numbers
    Returns:
      the tolerance

  - ### setTolerance

    public void setTolerance(double d)
    Sets the tolerance used for comparing complex numbers
    Parameters:
      `d` - the tolerance

  - ### getDescription

    public String getDescription()
    Description copied from class: `PostfixMathCommand`
    Return a description of the function from the properties file. The property name is the class name followed by ".description". The property is found using the `JepMessages` class, which can be configured to add additional properties files. If `PostfixMathCommand.setDescription(String)` has been called, return the description set by that method instead.
    Specified by:
      `getDescription` in interface `PostfixMathCommandI`
    Overrides:
      `getDescription` in class `PostfixMathCommand`
    Returns:
      the description of the function