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, java.io.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(new Double(1)); else inStack.push(new Double(0));
  Author:
    N Funk and R Morris
  See Also:
    Serialized Form

- - ### Field Summary

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

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

      `curNumberOfParameters, name, NaN, numberOfParameters`

  - ### Constructor Summary

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

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `compare(java.lang.Object param1, java.lang.Object param2)`
    `boolean` | `eq(java.lang.Object param1, java.lang.Object param2)`
    `java.lang.Object` | `eval(java.lang.Object l, java.lang.Object r)`
    `boolean` | `ge(java.lang.Object param1, java.lang.Object param2)`
    `int` | `getId()` Return the ID of the comparative operator
    `double` | `getTolerance()` Returns the tolerance used for comparing complex numbers
    `boolean` | `gt(java.lang.Object param1, java.lang.Object param2)`
    `boolean` | `le(java.lang.Object param1, java.lang.Object param2)`
    `boolean` | `lt(java.lang.Object param1, java.lang.Object param2)`
    `boolean` | `ne(java.lang.Object param1, java.lang.Object param2)`
    `void` | `setTolerance(double d)` Sets the tolerance used for comparing complex numbers

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

      `run`

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

      `asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkNumberOfParameters, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString, toString`

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

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

- - ### Field Detail

    - #### 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 Detail

    - #### 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 Detail

    - #### getId

          public int getId()

      Return the ID of the comparative operator
      Returns:
        the id code
      Since:
        3.5

    - #### eval

          public java.lang.Object eval(java.lang.Object l,
                                       java.lang.Object r)
                                throws EvaluationException

      Specified by:
        `eval` in class `BinaryFunction`
      Throws:
        `EvaluationException`

    - #### compare

          public boolean compare(java.lang.Object param1,
                                 java.lang.Object param2)
                          throws EvaluationException

      Throws:
        `EvaluationException`

    - #### lt

          public boolean lt(java.lang.Object param1,
                            java.lang.Object param2)
                     throws EvaluationException

      Throws:
        `EvaluationException`

    - #### gt

          public boolean gt(java.lang.Object param1,
                            java.lang.Object param2)
                     throws EvaluationException

      Throws:
        `EvaluationException`

    - #### le

          public boolean le(java.lang.Object param1,
                            java.lang.Object param2)
                     throws EvaluationException

      Throws:
        `EvaluationException`

    - #### ge

          public boolean ge(java.lang.Object param1,
                            java.lang.Object param2)
                     throws EvaluationException

      Throws:
        `EvaluationException`

    - #### eq

          public boolean eq(java.lang.Object param1,
                            java.lang.Object param2)
                     throws EvaluationException

      Throws:
        `EvaluationException`

    - #### ne

          public boolean ne(java.lang.Object param1,
                            java.lang.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

Copyright © 2018 Singular Systems http://www.singularsys.com/jep