|
mathExpr by jtem group |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectmathExpr.ExpressionConfiguration
An ExpressionConfiguration is a fundamental class for parsing
and evaluating Expressions. This class provides the
easiest way of working with the mathExpr library and it should be
your starting point whenever you decide to work with mathExpr
classes.
A single instance of this class is a representation of a single
Expression.
It eases parsing and evaluating by corresponding methods like
setExpression(String exp) or evaluateExpression().
You don't need to create a Parser or Evaluator - they were
created by this ExpressionConfiguration if necessary.
All you have to do is to choose a default Type (e.g.: ComplexType.TYPE) and construct
an ExpressionConfiguration.
For example:
Type defaultType=new ComplexType.TYPE; ExpressionConfiguration config=new ExpressionConfiguration(defaultType);
//parse the expression "2+2i" config.setExpression("2+2i");
//get the expression as an Expression object Expression exp=config.getExpression();
//evaluate the expression and get the result as an Object Object o=config.evaluateExpression();
...
If you use the constructor ExpressionConfiguration(Type), this
class creates a new DefinitionModel and a new ExpressionFactory parameterized with that DefinitionModel.
Use the other constructor, if you want to use a single
DefinitionModel for several
ExpressionConfigurations,
e.g.:
ExpressionConfiguration config1=new ExpressionConfiguration(ComplexType.TYPE); DefinitionModel defModel=config1.getDefinitionModel(); ExpressionConfiguration config2=new ExpressionConfiguration(ComplexType.TYPE, defModel); config1.defineVariable("a", new Complex(2), ComplexType.TYPE); config1.defineVariable("b", new Complex(4), ComplexType.TYPE); config1.setExpression("a+b"); //the next command is possible because the DefinitionModel of config1 and config2 is the same instance config2.setExpression("a*b");
| Constructor Summary | |
ExpressionConfiguration()
Creates a new ExpressionConfiguration instance with
ComplexType.TYPE as the Type for evaluating
Symbols. |
|
ExpressionConfiguration(DefinitionModel defModel)
Creates a new ExpressionConfiguration instance with
ComplexType.TYPE as the Type for evaluating
Symbols and
the specified DefinitionModel. |
|
ExpressionConfiguration(Type defaultType)
Creates a new ExpressionConfiguration instance with the
specified Type for evaluating Symbols. |
|
ExpressionConfiguration(Type defaultType,
DefinitionModel defModel)
Creates a new ExpressionConfiguration instance with the
specified Type for evaluating Symbols and
the specified DefinitionModel. |
|
| Method Summary | |
UserDefinedFunction |
defineFunction(java.lang.String name,
java.lang.String[] param,
Expression def)
Defines or changes a UserDefinedFunction by delegating the
method DefinitionModel.defineFunction(String,String[],Expression)
of this' DefinitionModel. |
UserDefinedFunction |
defineFunction(java.lang.String name,
java.lang.String[] param,
java.lang.String def)
Defines or changes a UserDefinedFunction by delegating the
method DefinitionModel.defineFunction(String,String[],Expression)
of this' DefinitionModel. |
Variable |
defineVariable(java.lang.String name,
java.lang.Object value,
Type type)
Defines or changes a Variable by delegating the method DefinitionModel.defineVariable(String,Object,Type) of this'
DefinitionModel. |
Expression |
differentiate(java.lang.String str)
Creates a new Symbol with String str and delegates to differentiate(Symbol) and returns the simplified derivative of
the current set Expression with respect to that Symbol. |
Expression |
differentiate(Symbol s)
Returns the simplified derivative of the current set Expression with respect to the Symbol s. |
Expression |
dissolveFunctionCalls()
Calls Expression.dissolveFunctionCalls() on the current
set Expression and returns the result. |
java.lang.Object |
evaluateExpression()
Evaluates the current Expression by calling the method Evaluator.evaluate() on the expression's Evaluator. |
DefinitionModel |
getDefinitionModel()
Returns the DefinitionModel holding all Variables and Functions. |
Evaluator |
getEvaluator()
Returns the Evaluator for the current Expression. |
Expression |
getExpression()
Returns the Expression this
ExpressionConfiguration currently represents or null
if an Expression wasn't set yet. |
ExpressionFactory |
getExpressionFactory()
Returns the ExpressionFactory which is neccessary for any
instantiated Parser. |
Type |
getType()
Returns the current default Type for evaluating Symbols. |
Variable |
getVariable(java.lang.String name)
Returns the Variable with the specified name by delegating the
method DefinitionModel.getVariable(String) of this'
DefinitionModel. |
Expression |
replaceSymbol(Symbol s,
Expression expr)
Calls Expression.replaceSymbol(Symbol, Expression) on the current
set Expression and returns the result. |
void |
setDefinitionModel(DefinitionModel newDefModel)
Sets a new DefinitionModel for this
ExpressionConfiguration. |
void |
setExpression(Expression exp)
Sets the Expression this ExpressionConfiguration
is to be representing. |
void |
setExpression(java.lang.String exp)
Sets the Expression this ExpressionConfiguration
is to be representing by parsing the specified String. |
void |
setType(Type type)
Sets a new default Type for evaluating Symbols. |
Expression |
simplify()
Returns the current set Expression simplified. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
public ExpressionConfiguration()
ExpressionConfiguration instance with
ComplexType.TYPE as the Type for evaluating
Symbols.
public ExpressionConfiguration(DefinitionModel defModel)
ExpressionConfiguration instance with
ComplexType.TYPE as the Type for evaluating
Symbols and
the specified DefinitionModel. Use this constructor if you
want to have more than one ExpressionConfiguration with
the same DefinitionModel.
defModel - the DefinitionModel to be used for this
ExpressionConfiguration.public ExpressionConfiguration(Type defaultType)
ExpressionConfiguration instance with the
specified Type for evaluating Symbols.
defaultType - the Type Symbols will
be evaluated to.
public ExpressionConfiguration(Type defaultType,
DefinitionModel defModel)
ExpressionConfiguration instance with the
specified Type for evaluating Symbols and
the specified DefinitionModel. Use this constructor if you
want to have more than one ExpressionConfiguration with
the same DefinitionModel.
defaultType - the Type Symbols will
be evaluated to.defModel - the DefinitionModel to be used for this
ExpressionConfiguration.| Method Detail |
public UserDefinedFunction defineFunction(java.lang.String name,
java.lang.String[] param,
Expression def)
throws IncompatibleDefinitionException
UserDefinedFunction by delegating the
method DefinitionModel.defineFunction(String,String[],Expression)
of this' DefinitionModel. See the documentation of that method
for details.
name - the name for the UserDefinedFunction to be defined
respectively the name of the UserDefinedFunction to be
changed.param - an array of names of the parameters for the
UserDefinedFunction to be defined respectively the new
parameters for the UserDefinedFunction to be changed.def - the definition for the UserDefinedFunction to be
defined respectively the new definition for the UserDefinedFunction
to be changed.
UserDefinedFunction which was defined respectively
changed.
IncompatibleDefinitionException - if a Variable with the same
name is already defined.getDefinitionModel()
public UserDefinedFunction defineFunction(java.lang.String name,
java.lang.String[] param,
java.lang.String def)
UserDefinedFunction by delegating the
method DefinitionModel.defineFunction(String,String[],Expression)
of this' DefinitionModel. See the documentation of that method
for details.
String def will be parsed before the delegation.
name - the name for the UserDefinedFunction to be defined
respectively the name of the UserDefinedFunction to be
changed.param - an array of names of the parameters for the
UserDefinedFunction to be defined respectively the new
parameters for the UserDefinedFunction to be changed.def - a String representing the definition for the
UserDefinedFunction to be defined respectively a
String representing the new definition for the
UserDefinedFunction to be changed.
UserDefinedFunction which was defined respectively
changed.
IncompatibleDefinitionException - if a Variable with the same
name is already defined.getDefinitionModel()
public Variable defineVariable(java.lang.String name,
java.lang.Object value,
Type type)
throws IncompatibleDefinitionException
Variable by delegating the method DefinitionModel.defineVariable(String,Object,Type) of this'
DefinitionModel. See the documentation of that method for
details.
name - the name for the Variable to be defined
respectively the name of the Variable to be changed.value - the value for the Variable to be defined
respectively the new value for the Variable to be changed.type - the Type for the Variable to be
defined respectively the new Type for the
Variable to be changed.
Variable which was defined respectively changed.
IncompatibleDefinitionException - if a Function with the same
name is already defined.getDefinitionModel()public Expression differentiate(java.lang.String str)
differentiate(Symbol) and returns the simplified derivative of
the current set Expression with respect to that Symbol.
Expression.simplify()public Expression differentiate(Symbol s)
java.lang.IllegalStateException - if no Expression was set yet.Expression.differentiate(Symbol),
Expression.simplify()public Expression dissolveFunctionCalls()
Expression.dissolveFunctionCalls() on the current
set Expression and returns the result.
public java.lang.Object evaluateExpression()
throws UnknownDefinitionException
Expression by calling the method Evaluator.evaluate() on the expression's Evaluator.
This method creates the evaluator-tree for the current expression
(the setted expression) if it's not already created (because this
method or the method getEvaluator() was already called).
After that it returns the evaluation result as an Object.
Object as the result of the evaluation.
UnknownDefinitionExceptiongetEvaluator(),
getExpression()public DefinitionModel getDefinitionModel()
DefinitionModel holding all Variables and Functions.
DefinitionModel of this
ExpressionConfiguration.defineVariable(String,Object,Type),
defineFunction(String,String[],String),
defineFunction(String,String[],Expression)public Evaluator getEvaluator()
Evaluator for the current Expression.
Evaluator for the current Expression.
java.lang.NullPointerException - if there is not an Expression
setted yet.setExpression(Expression),
setExpression(String)public Expression getExpression()
Expression this
ExpressionConfiguration currently represents or null
if an Expression wasn't set yet.
Expression this
ExpressionConfiguration currently represents.setExpression(Expression),
setExpression(String)public ExpressionFactory getExpressionFactory()
ExpressionFactory which is neccessary for any
instantiated Parser.
ExpressionFactory of this
ExpressionConfiguration.public Type getType()
Type for evaluating Symbols.
Type for evaluating Symbols.setType(Type),
evaluateExpression()public Variable getVariable(java.lang.String name)
Variable with the specified name by delegating the
method DefinitionModel.getVariable(String) of this'
DefinitionModel.
name - the name of the Variable this method tries to
return.
Variable with the specified name or
null if the Variable does not exist yet.getDefinitionModel()
public Expression replaceSymbol(Symbol s,
Expression expr)
Expression.replaceSymbol(Symbol, Expression) on the current
set Expression and returns the result.
public void setDefinitionModel(DefinitionModel newDefModel)
Sets a new DefinitionModel for this
ExpressionConfiguration.
Expression makes use
of some of these definitions. That's why the Expression
of this ExpressionConfiguration becomes null
if the method setDefinitionModel(DefinitionModel) is
calling. You have to reset it.
newDefModel - the DefinitionModel to be used for this
ExpressionConfiguration.setExpression(String),
setExpression(Expression),
getDefinitionModel()public void setExpression(Expression exp)
Expression this ExpressionConfiguration
is to be representing.
exp - the new Expression for this
ExpressionConfiguration.setExpression(String),
getExpression()public void setExpression(java.lang.String exp)
Expression this ExpressionConfiguration
is to be representing by parsing the specified String. See
documentation of class Parser to get information about the
syntax the specified String has to have.Parser. This method creates a
new Parser and sets the Expression of this
ExpressionConfiguration object to the parsed one.
exp - a String representing the new
Expression for this ExpressionConfiguration.getEvaluator(),
setExpression(Expression),
getExpression()public void setType(Type type)
Type for evaluating Symbols.
type - the new Type to be set.getType(),
evaluateExpression()public Expression simplify()
Expression.simplify().
java.lang.IllegalStateException - if no Expression was set yet.
|
mathExpr by jtem group |
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||