com.graphbuilder.math
Class FuncMap

java.lang.Object
  extended bycom.graphbuilder.math.FuncMap

public class FuncMap
extends java.lang.Object

FuncMap maps a name to a function. A FuncMap is used in the eval method of an Expression object. This class can be used as the default function-map. The loadDefaultFunctions() method can be used to take advantage of the many already implemented functions (see below).

During the evaluation of an expression, if a function is not supported then a RuntimeException is thrown.

Default functions:

No Parameters
1 Parameter
2 Parameters
n Parameters

Note: Case sensitivity can only be specified in the constructor (for consistency). When case sensitivity is false, the String.equalsIgnoreCase method is used. When case sensitivity is true, the String.equals method is used. The matching does not include the parenthesis. For example, when case sensitivity is false and the default functions have been loaded, then "RaNd", "rand", and "RAND" all map to the RandFunction(). By default, case sensitivity is false.


Constructor Summary
FuncMap()
           
FuncMap(boolean caseSensitive)
           
 
Method Summary
 Function getFunction(java.lang.String funcName, int numParam)
          Returns a function based on the name and the specified number of parameters.
 java.lang.String[] getFunctionNames()
          Returns an array of exact length of the function names stored in this map.
 Function[] getFunctions()
          Returns an array of exact length of the functions stored in this map.
 boolean isCaseSensitive()
          Returns true if the case of the function names is considered.
 void loadDefaultFunctions()
          Adds the mappings for many common functions.
 void remove(java.lang.String funcName)
          Removes the function-name and the associated function from the map.
 void setFunction(java.lang.String funcName, Function f)
          Assigns the name to map to the specified function.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FuncMap

public FuncMap()

FuncMap

public FuncMap(boolean caseSensitive)
Method Detail

loadDefaultFunctions

public void loadDefaultFunctions()
Adds the mappings for many common functions. The names are specified in all lowercase letters.


getFunction

public Function getFunction(java.lang.String funcName,
                            int numParam)
Returns a function based on the name and the specified number of parameters.

Throws:
java.lang.RuntimeException - If no supporting function can be found.

setFunction

public void setFunction(java.lang.String funcName,
                        Function f)
Assigns the name to map to the specified function.

Throws:
java.lang.IllegalArgumentException - If any of the parameters are null.

isCaseSensitive

public boolean isCaseSensitive()
Returns true if the case of the function names is considered.


getFunctionNames

public java.lang.String[] getFunctionNames()
Returns an array of exact length of the function names stored in this map.


getFunctions

public Function[] getFunctions()
Returns an array of exact length of the functions stored in this map. The returned array corresponds to the order of the names returned by getFunctionNames.


remove

public void remove(java.lang.String funcName)
Removes the function-name and the associated function from the map. Does nothing if the function-name is not found.