Jasmine  1.1
Super fast expression and algorithm evaluator
 All Classes Functions
org.quark.jasmine.Algorithm Class Referenceabstract
Inheritance diagram for org.quark.jasmine.Algorithm:

Public Member Functions

void clearVariables ()
 
void showVariables ()
 
void initVariables (Object...params)
 
Answer answer (String name)
 
abstract Algorithm eval (Object...vars)
 
- Public Member Functions inherited from org.quark.jasmine.AbstractExpression
 AbstractExpression ()
 
Answer answer ()
 
long getBuildTime ()
 
long getEvalTime ()
 
String infix ()
 
String ast ()
 
String bytecode ()
 

Protected Attributes

HashMap< String, Double > __vars = new HashMap<String, Double>()
 
- Protected Attributes inherited from org.quark.jasmine.AbstractExpression
long __buildTime
 
long __evalTime
 
Answer __answer
 
String infix
 
String ast
 
String bytecode
 

Private Member Functions

double toDouble (Object value)
 

Additional Inherited Members

- Protected Member Functions inherited from org.quark.jasmine.AbstractExpression
String makeInfix (List< Exp > infix)
 
String makeAST (Exp ast)
 
String makeAST (Deque< Exp > ast)
 
void mmakeASTimpl (Exp exp, String tab, StringBuilder sb)
 
String makeByteCode (byte[] b)
 

Detailed Description

An algorithm is a series of statements on one or more lines that can be evaluated.

Algorithm extends the capabilities of the Expression class by providing support for variables, selection and iteration constructs. Unlike expression, algorithms does not return a single value, rather you can examine any of the variables after evaluation.

Author
Peter Lager

Member Function Documentation

Answer org.quark.jasmine.Algorithm.answer ( String  name)

Use this to get the value stored in a variable after evaluation has finished.

Parameters
namethe name of the variable
Returns
the value of a variable wrapped in an answer object or null if the variable doen't exist.
void org.quark.jasmine.Algorithm.clearVariables ( )

Initialize all the variables to zero. The variables are not cleared before or after an evaluation so that variable data persists between evaluations. If you don't want the data to persist call this method before calling eval(...)

abstract Algorithm org.quark.jasmine.Algorithm.eval ( Object...  vars)
pure virtual

Jasmine using ASM to generate the code for this method.

The parameters represent the initial values to be used for the evaluation and are expressed as pairs "variable _name", variable+value. For instnace

("m", 4.6, "pi2", 2 * Math.PI)


will initialise the variables m and pi2 to 4.6 and 6.283185307

This method returns 'this' so for example you can chain like this:

algorithm.eval("m", 4.6, "pi2", 2 * Math.PI).answer("m").toFloat(); 

to get the value stored in 'm' as a float.

Parameters
varsthe initial values to use in this evaluation
Returns
this Algorithm
void org.quark.jasmine.Algorithm.initVariables ( Object...  params)

This method is called for you when the algorithm is evaluated so it is recommended that you do this by passing initial variable state in the parameters for eval(initial_variable_state)

void org.quark.jasmine.Algorithm.showVariables ( )

Display all the variables and their values in the console window.

double org.quark.jasmine.Algorithm.toDouble ( Object  value)
private

This is used to convert any value passed by the user to a double. It accepts data of any type and attempt to convert it to a double. If it's not possible it returns 0.0


The documentation for this class was generated from the following file: