rafa.math.gen
Class Function

java.lang.Object
  extended by rafa.math.gen.Function
All Implemented Interfaces:
java.beans.PropertyChangeListener, java.util.EventListener, Dependent

public class Function
extends java.lang.Object
implements Dependent, java.beans.PropertyChangeListener

Wrapper around a MESP parser, which simplifies the task of retrieving automatically non-default functions from named generators in the NameRegistry.

Author:
rafa

Field Summary
protected static java.lang.String[] DEFAULTS
          The default function names as provided by MESP's FuncMap.loadDefaultFunctions().
protected static java.lang.String X
          The independent variable
 
Constructor Summary
Function(java.lang.String function)
           
Function(java.lang.String function, java.util.Map<java.lang.String,java.lang.Number> vars, java.util.Map<java.lang.String,java.util.List<? extends java.lang.Number>> funcs)
           
 
Method Summary
protected  void checkName(java.lang.String name)
          Checks that a function name is valid for the parser.
 java.util.Collection<Dependency> getDependencies(java.lang.Object target)
          Gets detailed information about the dependencies of this object on a given one.
protected  java.util.List<java.lang.String> getFunctionNames()
          Retrieves the names of the functions (helpers) actually used by this one, i.e.
 double getValue(double xValue, boolean refreshFunctions)
          Gets the function value for a given value of x.
protected  void loadFuncMap()
          Loads every known function - predefined by MESP and user-defined (in the name registry) - for later use.
protected  void loadFuncMap(java.util.Map<java.lang.String,java.util.List<? extends java.lang.Number>> funcs)
          Loads functions which may be used as helpers.
 void loadFunction(java.lang.String n)
          Loads one helper function from the name registry into the function map.
 void loadFunction(java.lang.String f, java.util.List<? extends java.lang.Number> list)
          Loads a list of numbers to be used as a helper function by this one.
 void loadVariable(java.lang.String name, java.lang.Number value)
          Loads a variable to be used from this function.
protected  void loadVarMap(java.util.Map<java.lang.String,java.lang.Number> vars)
           
protected  void parse(java.lang.String function)
          Updates the function expression.
protected  void parse(java.lang.String function, java.util.Map<java.lang.String,java.lang.Number> vars, java.util.Map<java.lang.String,java.util.List<? extends java.lang.Number>> funcs)
           
 void propertyChange(java.beans.PropertyChangeEvent e)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

X

protected static final java.lang.String X
The independent variable

See Also:
Constant Field Values

DEFAULTS

protected static final java.lang.String[] DEFAULTS
The default function names as provided by MESP's FuncMap.loadDefaultFunctions().

Constructor Detail

Function

public Function(java.lang.String function)

Function

public Function(java.lang.String function,
                java.util.Map<java.lang.String,java.lang.Number> vars,
                java.util.Map<java.lang.String,java.util.List<? extends java.lang.Number>> funcs)
Method Detail

loadVarMap

protected void loadVarMap(java.util.Map<java.lang.String,java.lang.Number> vars)

loadFuncMap

protected void loadFuncMap()
Loads every known function - predefined by MESP and user-defined (in the name registry) - for later use.


loadFuncMap

protected void loadFuncMap(java.util.Map<java.lang.String,java.util.List<? extends java.lang.Number>> funcs)
Loads functions which may be used as helpers. These are taken from MESP (predefined), the name registry (user-defined, global scope) and the passed parameter (user-defined, local scope).

Parameters:
funcs - the functions to be used locally in this one (not shared with any others).

loadFunction

public void loadFunction(java.lang.String n)
Loads one helper function from the name registry into the function map.

Parameters:
n - The name of the function (generator) as stored in the name registry.

loadFunction

public void loadFunction(java.lang.String f,
                         java.util.List<? extends java.lang.Number> list)
Loads a list of numbers to be used as a helper function by this one. Example: if the list [ 11, 22, 33, 44 ] is passed with the name foo, the string foo(0) will evaluate to 11 and foo(3) to 33.

Parameters:
f - the name given to the function.
list - A list of numbers. If null, the NameRegistry is searched for the name to get a number generator.

loadVariable

public void loadVariable(java.lang.String name,
                         java.lang.Number value)
Loads a variable to be used from this function. If already existing, it is overwritten.

Parameters:
name - the variable name.
value - the variable value.

getValue

public double getValue(double xValue,
                       boolean refreshFunctions)
Gets the function value for a given value of x.

Parameters:
xValue - the value assigned to the x variable in the expression.
refreshFunctions - should the function map be refreshed?
Returns:
the value of the function.

parse

protected void parse(java.lang.String function)
Updates the function expression.

Parameters:
function -

parse

protected void parse(java.lang.String function,
                     java.util.Map<java.lang.String,java.lang.Number> vars,
                     java.util.Map<java.lang.String,java.util.List<? extends java.lang.Number>> funcs)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getFunctionNames

protected java.util.List<java.lang.String> getFunctionNames()
Retrieves the names of the functions (helpers) actually used by this one, i.e. those which appear in the function expression.

Returns:
A list of function names.

checkName

protected void checkName(java.lang.String name)
                  throws InvalidNameException
Checks that a function name is valid for the parser. Note that it does not check for existing generator names - which is already done by NameRegistry, but only for existing predefined default functions (see DEFAULTS).

Parameters:
name - a function name
Throws:
ExistingNameException - if the name collides with a predefined function name.
InvalidNameException - if the name is not valid.

getDependencies

public java.util.Collection<Dependency> getDependencies(java.lang.Object target)
Description copied from interface: Dependent
Gets detailed information about the dependencies of this object on a given one.

Specified by:
getDependencies in interface Dependent
Parameters:
target - the required object. If null, all of the dependencies will be returned.
Returns:
a collection of Dependency objects pointing to the same object (target), or null if there is no dependency on that object.

propertyChange

public void propertyChange(java.beans.PropertyChangeEvent e)
Specified by:
propertyChange in interface java.beans.PropertyChangeListener


Copyright © 2008-2009. All Rights Reserved.