net.sourceforge.webcompmath.functions.beans
Class WCMExpressionFunctionBean

java.lang.Object
  extended by net.sourceforge.webcompmath.functions.FunctionParserExtension
      extended by net.sourceforge.webcompmath.functions.ExpressionFunction
          extended by net.sourceforge.webcompmath.functions.beans.WCMExpressionFunctionBean
All Implemented Interfaces:
java.io.Serializable, ParserMathObject, ExpressionCommand, Function, MathObject, ParserExtension, Value

public class WCMExpressionFunctionBean
extends ExpressionFunction
implements Value, ParserMathObject

This bean extends ExpressionFunction. You need to set its definition before it will do anything. By default, it uses a default parser with one variable, "x". If you want to use more variables in the definition, set the parser to one that has those additional variables set for it. You can use this bean as either an expression, where it is just evaluated at the current values of any parameters in it, or as a function (and hence you can graph it by adding it to a WCMGraph1DBean). If you add this bean to a parser, you can then use it like a function (change the default name if you would like something other than "ef1").

Author:
Tom Downey
See Also:
Serialized Form

Field Summary
 
Fields inherited from class net.sourceforge.webcompmath.functions.ExpressionFunction
definition, params
 
Fields inherited from class net.sourceforge.webcompmath.functions.FunctionParserExtension
name
 
Constructor Summary
WCMExpressionFunctionBean()
          Default constructor; creates a WCMExpressionFunctionBean with default name efX (where X is some integer) and a definition of "0".
 
Method Summary
 void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
          Just pass through to the support class
 void apply(StackOfDouble stack, Cases cases)
          Overridden to check if a redefine is needed.
 boolean dependsOn(Variable x)
          Overridden to check if a redefine is needed.
 Function derivative(int wrt)
          Overridden to check if a redefine is needed.
 Function derivative(Variable x)
          Overridden to check if a redefine is needed.
 java.lang.String getDefinitionString()
          Overridden to check if a redefine is needed.
 MathObject getMathObject()
          Since this is a ParserExtension, just returns itself.
 int getNumVariables()
          Just pass this method on to the super class.
 WCMParserBean getParser()
          Get the parser
 double getVal()
          get the value (for use when this represents an expression, not a function
 double getValueWithCases(double[] arguments, Cases cases)
          Overridden to check if a redefine is needed.
 Variable getVariable()
          Get the first variable to be used when this class is treaded as a function of one or two variables.
 Variable getVariable2()
          Get the 2nd variable to be used when this class is treaded as a function of two variables.
 void redefine()
          Overloads the version of redefine so that the WCMExpressionFunctionBean's parser is always used.
 void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
          just pass through to the support class )
 void setDefinition(java.lang.String def)
          Set the definition of the expression
 void setName(java.lang.String name)
          Fire a property change event if the name changes.
 void setNumVariables(int a)
          Set the arity, which can be either 1 or 2.
 void setParser(WCMParserBean p)
          Set the parser
 void setVariable(WCMVariableBean v)
          Set the first variable to be used when this class is treated as a function of one or two variables.
 void setVariable2(WCMVariableBean v)
          Set the 2nd variable to be used when this class is treated as a function of two variables.
 java.lang.String toString()
          get a text representation of this function.
 
Methods inherited from class net.sourceforge.webcompmath.functions.ExpressionFunction
getArity, getVal, redefine, redefine
 
Methods inherited from class net.sourceforge.webcompmath.functions.FunctionParserExtension
appendOutputString, compileDerivative, doParse, extent, getName, setParensCanBeOptional
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sourceforge.webcompmath.data.MathObject
getName
 

Constructor Detail

WCMExpressionFunctionBean

public WCMExpressionFunctionBean()
Default constructor; creates a WCMExpressionFunctionBean with default name efX (where X is some integer) and a definition of "0". Uses a default parser.

Method Detail

setVariable

public void setVariable(WCMVariableBean v)
Set the first variable to be used when this class is treated as a function of one or two variables.

Parameters:
v -

getVariable

public Variable getVariable()
Get the first variable to be used when this class is treaded as a function of one or two variables.

Returns:
the variable

setVariable2

public void setVariable2(WCMVariableBean v)
Set the 2nd variable to be used when this class is treated as a function of two variables.

Parameters:
v -

getVariable2

public Variable getVariable2()
Get the 2nd variable to be used when this class is treaded as a function of two variables.

Returns:
the variable

getNumVariables

public int getNumVariables()
Just pass this method on to the super class.

Returns:
1 or 2

setNumVariables

public void setNumVariables(int a)
Set the arity, which can be either 1 or 2. If you need a function of more than 2 variables, you will need to hand code.

Parameters:
a - either 1 or 2

setParser

public void setParser(WCMParserBean p)
Set the parser

Parameters:
p - the parser to use

getParser

public WCMParserBean getParser()
Get the parser

Returns:
the parser

setDefinition

public void setDefinition(java.lang.String def)
Set the definition of the expression

Parameters:
def - the new definition

getVal

public double getVal()
get the value (for use when this represents an expression, not a function

Specified by:
getVal in interface Value
Returns:
object's value
See Also:
Value.getVal()

getMathObject

public MathObject getMathObject()
Since this is a ParserExtension, just returns itself.

Specified by:
getMathObject in interface ParserMathObject
Returns:
the MathObject that will be added to a parser
See Also:
ParserMathObject.getMathObject()

toString

public java.lang.String toString()
get a text representation of this function. Just returns the definition string.

Overrides:
toString in class ExpressionFunction
Returns:
string representation of the function
See Also:
ExpressionFunction.toString()

redefine

public void redefine()
Overloads the version of redefine so that the WCMExpressionFunctionBean's parser is always used.

See Also:
ExpressionFunction.redefine(java.lang.String, net.sourceforge.webcompmath.data.Parser)

apply

public void apply(StackOfDouble stack,
                  Cases cases)
Overridden to check if a redefine is needed.

Specified by:
apply in interface ExpressionCommand
Overrides:
apply in class ExpressionFunction
Parameters:
stack - stack to use
cases - cases to use
See Also:
ExpressionFunction.apply(net.sourceforge.webcompmath.data.StackOfDouble, net.sourceforge.webcompmath.data.Cases)

dependsOn

public boolean dependsOn(Variable x)
Overridden to check if a redefine is needed.

Specified by:
dependsOn in interface ExpressionCommand
Specified by:
dependsOn in interface Function
Overrides:
dependsOn in class ExpressionFunction
Parameters:
x - variable to check
Returns:
true or false
See Also:
ExpressionFunction.dependsOn(net.sourceforge.webcompmath.data.Variable)

derivative

public Function derivative(int wrt)
Overridden to check if a redefine is needed.

Specified by:
derivative in interface Function
Overrides:
derivative in class ExpressionFunction
Parameters:
wrt - index of the arg. with respect to
Returns:
the derivative
See Also:
ExpressionFunction.derivative(int)

derivative

public Function derivative(Variable x)
Overridden to check if a redefine is needed.

Specified by:
derivative in interface Function
Overrides:
derivative in class ExpressionFunction
Parameters:
x - variable with respect to
Returns:
the derivative
See Also:
ExpressionFunction.derivative(net.sourceforge.webcompmath.data.Variable)

getDefinitionString

public java.lang.String getDefinitionString()
Overridden to check if a redefine is needed.

Overrides:
getDefinitionString in class ExpressionFunction
Returns:
definition of the function
See Also:
ExpressionFunction.getDefinitionString()

getValueWithCases

public double getValueWithCases(double[] arguments,
                                Cases cases)
Overridden to check if a redefine is needed.

Specified by:
getValueWithCases in interface Function
Overrides:
getValueWithCases in class ExpressionFunction
Parameters:
arguments - array of args. to use in evaluation
cases - cases to use
Returns:
the value
See Also:
ExpressionFunction.getValueWithCases(double[], net.sourceforge.webcompmath.data.Cases)

addPropertyChangeListener

public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Just pass through to the support class

Specified by:
addPropertyChangeListener in interface ParserMathObject
See Also:
ParserMathObject.addPropertyChangeListener(java.beans.PropertyChangeListener)

removePropertyChangeListener

public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
just pass through to the support class )

Specified by:
removePropertyChangeListener in interface ParserMathObject
See Also:
ParserMathObject.removePropertyChangeListener(java.beans.PropertyChangeListener)

setName

public void setName(java.lang.String name)
Fire a property change event if the name changes.

Specified by:
setName in interface MathObject
Overrides:
setName in class FunctionParserExtension
Parameters:
name - name of the object
See Also:
FunctionParserExtension.setName(java.lang.String)