org.nfunk.jep.function
Class Comparative

java.lang.Object
  extended by org.nfunk.jep.function.PostfixMathCommand
      extended by org.nfunk.jep.function.Comparative
All Implemented Interfaces:
PostfixMathCommandI
Direct Known Subclasses:
ElementComparative

public class Comparative
extends PostfixMathCommand

Implements the comparative operations <, >, <=, >=, != and ==. Caverts should work where arguments are Double, Complex or String for the last two only != and == work. 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

Field Summary
static int EQ
           
static int GE
           
static int GT
           
protected  int id
           
static int LE
           
static int LT
           
static int NE
           
 
Fields inherited from class org.nfunk.jep.function.PostfixMathCommand
curNumberOfParameters, numberOfParameters
 
Constructor Summary
Comparative(int id_in)
          Constructor.
 
Method Summary
 boolean eq(java.lang.Object param1, java.lang.Object param2)
           
 boolean ge(java.lang.Object param1, java.lang.Object param2)
           
 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 run(java.util.Stack inStack)
          Throws an exception because this method should never be called under normal circumstances.
 void setTolerance(double d)
          Sets the tolerance used for comparing complex numbers
 
Methods inherited from class org.nfunk.jep.function.PostfixMathCommand
checkNumberOfParameters, checkStack, getNumberOfParameters, setCurNumberOfParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

id

protected int id

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.
Method Detail

run

public void run(java.util.Stack inStack)
         throws ParseException
Description copied from class: PostfixMathCommand
Throws an exception because this method should never be called under normal circumstances. Each function should use it's own run() method for evaluating the function. This includes popping off the parameters from the stack, and pushing the result back on the stack.

Specified by:
run in interface PostfixMathCommandI
Overrides:
run in class PostfixMathCommand
Throws:
ParseException

lt

public boolean lt(java.lang.Object param1,
                  java.lang.Object param2)
           throws ParseException
Throws:
ParseException

gt

public boolean gt(java.lang.Object param1,
                  java.lang.Object param2)
           throws ParseException
Throws:
ParseException

le

public boolean le(java.lang.Object param1,
                  java.lang.Object param2)
           throws ParseException
Throws:
ParseException

ge

public boolean ge(java.lang.Object param1,
                  java.lang.Object param2)
           throws ParseException
Throws:
ParseException

eq

public boolean eq(java.lang.Object param1,
                  java.lang.Object param2)
           throws ParseException
Throws:
ParseException

ne

public boolean ne(java.lang.Object param1,
                  java.lang.Object param2)
           throws ParseException
Throws:
ParseException

getTolerance

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


setTolerance

public void setTolerance(double d)
Sets the tolerance used for comparing complex numbers

Parameters:
d -


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