com.singularsys.jep.functions
Class NaryBinaryFunction

java.lang.Object
  extended by com.singularsys.jep.functions.PostfixMathCommand
      extended by com.singularsys.jep.functions.NaryBinaryFunction
All Implemented Interfaces:
PostfixMathCommandI, java.io.Serializable
Direct Known Subclasses:
Add, BigDecAdd, BigDecMul, Concat, Multiply

public abstract class NaryBinaryFunction
extends PostfixMathCommand

Convenient base class for n-ary functions backed by a binary operation. Defines an Object eval(Object l,Object r) method for calculating the result. The operation must be associative.

Author:
Richard Morris
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.singularsys.jep.functions.PostfixMathCommand
curNumberOfParameters, name, NaN, numberOfParameters
 
Constructor Summary
NaryBinaryFunction()
           
 
Method Summary
 boolean checkNumberOfParameters(int n)
          Checks the number of parameters of the function.
 java.lang.Object eval(java.lang.Object[] args)
           
abstract  java.lang.Object eval(java.lang.Object l, java.lang.Object r)
           
 void run(java.util.Stack<java.lang.Object> stack)
          Calls eval(Object, Object)
 
Methods inherited from class com.singularsys.jep.functions.PostfixMathCommand
asArray, asBool, asDouble, asInt, asLong, asStrictInt, asString, checkStack, getName, getNumberOfParameters, setCurNumberOfParameters, setName, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NaryBinaryFunction

public NaryBinaryFunction()
Method Detail

checkNumberOfParameters

public boolean checkNumberOfParameters(int n)
Description copied from class: PostfixMathCommand
Checks the number of parameters of the function. Functions which set numberOfParameter=-1 should overload this method

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.

run

public final void run(java.util.Stack<java.lang.Object> stack)
               throws EvaluationException
Calls eval(Object, Object)

Throws:
EvaluationException

eval

public final java.lang.Object eval(java.lang.Object[] args)
                            throws EvaluationException
Throws:
EvaluationException

eval

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


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