com.bestcode.mathparser
Class OneParamFunc

java.lang.Object
  |
  +--com.bestcode.mathparser.OneParamFunc
All Implemented Interfaces:
IFunction

public abstract class OneParamFunc
extends java.lang.Object
implements IFunction

OneParamFunc abstract class represents a user defined callback function that takes one parameter. This is a convenience implementation of IFunction interface. During evaluation of an expression, MathParser calls OneParamFunc.run(IParameter[] p) to request the value of the function when it takes p[0] as parameter. For example, a user could define a function like this:

public class MyFunc extends OneParamFunc {
   public double run(IParameter[] p){
     return do_something_with_x( p[0] );
   }
}


User defined functions can be registered using createFunc method of MathParser. Example:
mathParser.createFunc("myfunc", new MyFunc());


Constructor Summary
OneParamFunc()
           
 
Method Summary
 int getNumberOfParams()
          This method returns the length of the parameters array that will be passed to the run(IParameter[]) method.
For example, for a function like F(X, Y, Z), this function should return 3.
abstract  double run(IParameter[] p)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OneParamFunc

public OneParamFunc()
Method Detail

getNumberOfParams

public int getNumberOfParams()
Description copied from interface: IFunction
This method returns the length of the parameters array that will be passed to the run(IParameter[]) method.
For example, for a function like F(X, Y, Z), this function should return 3.

Specified by:
getNumberOfParams in interface IFunction

run

public abstract double run(IParameter[] p)
Specified by:
run in interface IFunction