edu.buffalo.fs7.mathlib
Class Mathlib

java.lang.Object
  |
  +--edu.buffalo.fs7.mathlib.Mathlib
All Implemented Interfaces:
MathlibEventListener

public class Mathlib
extends java.lang.Object
implements MathlibEventListener

The Mathlib class needs to be instantiated in order to use all mathlib package features as variables, functions etc. The class initializes mathematical constants and registers functions coming along in the mathpackage. It implements a couple of static functions for the access to those variables and functions, which are used by the Parse object.


Field Summary
protected static java.util.Hashtable categories
          this hashtable provides categories for variables
protected static java.util.Hashtable functions
          This variable holds the defined functions
protected static java.util.Vector listeners
          this vector holds computation event listeners
protected static java.util.Random random
           
protected static java.util.Hashtable vars
          This variable holds the defined variables
 
Constructor Summary
Mathlib()
          This constructor initializes the hashtables for variables and functions that might be used in algebraic expressions.
 
Method Summary
static void addComputationEventListener(ComputationEventListener m)
          registers a ComputationEventListener
static void addMathlibEventListener(MathlibEventListener listener)
          wrapper method...
 void addVariable(MathlibEvent e)
          required by the MathlibEventListener interface.
 void changeVariable(MathlibEvent e)
          required by the MathlibEventListener interface.
 java.lang.String evaluateExpression(java.lang.String str)
          This function wraps the evaluateExpression function of the Parse class.
static void fireComputationEvent(MathObject operator, MathObject var, int currentStep, int maxStep, int action)
          creates a ComputationEvent and pumps it to processEvent
static java.lang.String getCategory(java.lang.String key)
          returns the category of a variable.
static MathMap getFunction(java.lang.String key)
          This function is called for example by the class Parse in order to check expressions for beeing a function and obtaining its representation.
 java.util.Enumeration getFunctions()
          returns a Enumeration object of all function names
static java.util.Random getRandom()
          returns the random object of the mathlib class
static MathObject getVar(java.lang.String key)
          This function is called for example by the class Parse in order to check expressions for beeing a variable and obtaining its value.
 java.util.Enumeration getVars()
          returns a Enumeration object of all variable names
 void listSystem()
          This function lists the system variables with their corresponding values.
 void listVars()
          This function lists all registered variables of the Mathlib object.
protected static void processEvent(ComputationEvent event)
          is called internally by fireMathlibEvent in order to dispatch the event
static void putVar(java.lang.String key, MathObject m)
          This function is called for example by the class Parse in order to register a new variable after recognizing an assignment expression.
static void removeComputationEventListener(ComputationEventListener m)
          removes a ComputationEventListener
static void removeMathlibEventListener(MathlibEventListener listener)
          wrapper method...
static void removeVar(java.lang.String key)
          This function is removes a variable from the variable list.
 void removeVariable(MathlibEvent e)
          required by the MathlibEventListener interface.
 void setCategory(java.lang.String category)
           
 void updateSystem()
          This function looks for system variables in the vars hashtable and assigns their value to the corresponding internal system variables.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

vars

protected static java.util.Hashtable vars
This variable holds the defined variables

categories

protected static java.util.Hashtable categories
this hashtable provides categories for variables

listeners

protected static java.util.Vector listeners
this vector holds computation event listeners

functions

protected static java.util.Hashtable functions
This variable holds the defined functions

random

protected static java.util.Random random
Constructor Detail

Mathlib

public Mathlib()
This constructor initializes the hashtables for variables and functions that might be used in algebraic expressions. It defines certain variables and registers available functions. It as well instatiates a parser object. If this constructor is not called, the parsing part of the mathlib package cannot be used.
Method Detail

putVar

public static void putVar(java.lang.String key,
                          MathObject m)
                   throws java.util.MissingResourceException
This function is called for example by the class Parse in order to register a new variable after recognizing an assignment expression. It throws an exception, if the Mathlib class has not been instantiated.
Parameters:
key - name of the variable
m - name of the MathObject
See Also:
Parse, MathObject

removeVar

public static void removeVar(java.lang.String key)
                      throws java.util.MissingResourceException
This function is removes a variable from the variable list. It throws an exception, if the Mathlib class has not been instantiated.
Parameters:
key - name of the variable
See Also:
removeVariable(MathlibEvent), MathObject

getVar

public static MathObject getVar(java.lang.String key)
                         throws java.util.MissingResourceException
This function is called for example by the class Parse in order to check expressions for beeing a variable and obtaining its value. It throws an exception, if the Mathlib class has not been instantiated.
Parameters:
key - name of the variable
Returns:
MathObject
See Also:
Parse

getCategory

public static java.lang.String getCategory(java.lang.String key)
                                    throws java.util.MissingResourceException
returns the category of a variable. It throws an exception, if the Mathlib class has not been instantiated.
Parameters:
key - name of the variable
Returns:
MathObject
See Also:
Parse

getFunction

public static MathMap getFunction(java.lang.String key)
                           throws java.util.MissingResourceException
This function is called for example by the class Parse in order to check expressions for beeing a function and obtaining its representation. It throws an exception, if the Mathlib class has not been instantiated.
Parameters:
key - name of the variable
Returns:
MathMap
See Also:
Parse, MathMap

evaluateExpression

public java.lang.String evaluateExpression(java.lang.String str)
                                    throws java.lang.IllegalArgumentException
This function wraps the evaluateExpression function of the Parse class. It takes care of system variables and updates them.
Parameters:
str - String to parse and evaluate
Returns:
returns the name (key) of the variable to which the expression was assigned.
See Also:
Parse.evaluateExpression(java.lang.String)

getVars

public java.util.Enumeration getVars()
returns a Enumeration object of all variable names

getFunctions

public java.util.Enumeration getFunctions()
returns a Enumeration object of all function names

getRandom

public static java.util.Random getRandom()
returns the random object of the mathlib class

listVars

public void listVars()
This function lists all registered variables of the Mathlib object.

listSystem

public void listSystem()
This function lists the system variables with their corresponding values.

updateSystem

public void updateSystem()
This function looks for system variables in the vars hashtable and assigns their value to the corresponding internal system variables.

removeVariable

public void removeVariable(MathlibEvent e)
required by the MathlibEventListener interface. It reacts to a MathlibEvent.
Specified by:
removeVariable in interface MathlibEventListener
Parameters:
MathlibEvent - event

addVariable

public void addVariable(MathlibEvent e)
required by the MathlibEventListener interface. It reacts to a MathlibEvent.
Specified by:
addVariable in interface MathlibEventListener
Parameters:
MathlibEvent - event

changeVariable

public void changeVariable(MathlibEvent e)
required by the MathlibEventListener interface. It reacts to a MathlibEvent.
Specified by:
changeVariable in interface MathlibEventListener
Parameters:
MathlibEvent - event

addMathlibEventListener

public static void addMathlibEventListener(MathlibEventListener listener)
wrapper method...
See Also:
Parse.addMathlibEventListener(MathlibEventListener)

removeMathlibEventListener

public static void removeMathlibEventListener(MathlibEventListener listener)
wrapper method...
See Also:
Parse.addMathlibEventListener(MathlibEventListener)

setCategory

public void setCategory(java.lang.String category)

addComputationEventListener

public static void addComputationEventListener(ComputationEventListener m)
registers a ComputationEventListener
Parameters:
m - listener object

removeComputationEventListener

public static void removeComputationEventListener(ComputationEventListener m)
removes a ComputationEventListener

processEvent

protected static void processEvent(ComputationEvent event)
is called internally by fireMathlibEvent in order to dispatch the event
Parameters:
e - ComputationEvent to dispatch

fireComputationEvent

public static void fireComputationEvent(MathObject operator,
                                        MathObject var,
                                        int currentStep,
                                        int maxStep,
                                        int action)
creates a ComputationEvent and pumps it to processEvent
Parameters:
operator - the operator causing the event
objectName - name of the variable computed
currentStep - current step of computation
maxStep - maximum step of computation
the - action to perform