visad.formula
Class FormulaManager

java.lang.Object
  extended byvisad.formula.FormulaManager

public class FormulaManager
extends Object

The FormulaManager class is the gateway into the visad.formula package, a general-purpose formula parser and evaluator. Variables update automatically when the variables upon which they depend change. For an example of usage, see the FormulaUtil.createStandardManager() method.


Field Summary
(package private)  Method[] bMethods
          binary method signatures
(package private)  String[] bOps
          binary operators
(package private)  int[] bPrec
          binary operator precedences
(package private)  Method[] fMethods
          function method signatures
(package private)  String[] funcs
          function names
(package private)  Method[] iMethods
          implicit function methods
(package private)  int iPrec
          implicit function precedence
(package private)  Method ppMethod
          formula text pre-parsing method.
(package private)  Method[] uMethods
          unary method signatures
(package private)  String[] uOps
          unary operators
(package private)  int[] uPrec
          unary operator precedences
 
Constructor Summary
FormulaManager(String[] binOps, int[] binPrec, String[] binMethods, String[] unaryOps, int[] unaryPrec, String[] unaryMethods, String[] functions, String[] funcMethods, int implicitPrec, String[] implicitMethods, String preParseMethod)
          construct a new FormulaManager object
 
Method Summary
 void assignFormula(String name, String formula)
          assign a formula to a variable
 boolean canBeRemoved(String name)
          check whether it is safe to remove a variable from the database
 void createVar(String name, ThingReference tr)
          add a variable to the database that uses tr as its ThingReference
 boolean exists(String name)
          check whether a given variable is currently in the database
(package private)  int getBinaryPrec(String op)
          returns a binary operator's level of precedence
 String[] getErrors(String name)
          get the current list of errors that occurred when evaluating "name" and clear the list
 String getFormula(String name)
          get a variable's current formula
 ThingReference getReference(String name)
          get a variable's associated ThingReference
 Thing getThing(String name)
          get a variable's current value
(package private)  int getUnaryPrec(String op)
          returns a unary operator's level of precedence
(package private)  FormulaVar getVarByName(String name)
          return the variable "name"
(package private)  FormulaVar getVarByNameOrCreate(String name)
          return the variable "name", creating it if necessary
(package private)  boolean isBinaryOp(String op)
          identify whether a given token is a binary operator
(package private)  boolean isFunction(String token)
          identify whether a given token is a defined function
(package private)  boolean isUnaryOp(String op)
          identify whether a given token is a unary operator
 void remove(String name)
          remove a variable from the database
 void setReference(String name, ThingReference tr)
          set a variable's ThingReference
 void setTextRef(String name, ThingReference textRef)
          set a variable to auto-update its formula based on a Text object referenced by a ThingReference (useful for remote formula updates)
 void setThing(String name, Thing t)
          set a variable's value directly
 void waitForFormula(String name)
          blocks until this variable's formula is finished computing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bOps

String[] bOps
binary operators


bPrec

int[] bPrec
binary operator precedences


bMethods

Method[] bMethods
binary method signatures


uOps

String[] uOps
unary operators


uPrec

int[] uPrec
unary operator precedences


uMethods

Method[] uMethods
unary method signatures


funcs

String[] funcs
function names


fMethods

Method[] fMethods
function method signatures


iPrec

int iPrec
implicit function precedence


iMethods

Method[] iMethods
implicit function methods


ppMethod

Method ppMethod
formula text pre-parsing method. For an application to support unusual non-standard syntaxes, such as brackets (e.g., VAR[0]), that application should supply a "pre-parsing" method in the preParseMethod argument, which converts non-standard syntax to standard syntax (e.g., VAR[0] could become getElement(VAR, 0)). The supplied method should be a static method taking a String argument (the formula) and a FormulaManager argument (this FormulaManager). If the application does not need such functionality, the preParseMethod argument can be null.

Constructor Detail

FormulaManager

public FormulaManager(String[] binOps,
                      int[] binPrec,
                      String[] binMethods,
                      String[] unaryOps,
                      int[] unaryPrec,
                      String[] unaryMethods,
                      String[] functions,
                      String[] funcMethods,
                      int implicitPrec,
                      String[] implicitMethods,
                      String preParseMethod)
               throws FormulaException
construct a new FormulaManager object

Method Detail

createVar

public void createVar(String name,
                      ThingReference tr)
               throws VisADException
add a variable to the database that uses tr as its ThingReference

Throws:
VisADException

assignFormula

public void assignFormula(String name,
                          String formula)
                   throws VisADException
assign a formula to a variable

Throws:
VisADException

waitForFormula

public void waitForFormula(String name)
                    throws VisADException
blocks until this variable's formula is finished computing

Throws:
VisADException

setTextRef

public void setTextRef(String name,
                       ThingReference textRef)
                throws VisADException,
                       RemoteException
set a variable to auto-update its formula based on a Text object referenced by a ThingReference (useful for remote formula updates)

Throws:
VisADException
RemoteException

getErrors

public String[] getErrors(String name)
get the current list of errors that occurred when evaluating "name" and clear the list


canBeRemoved

public boolean canBeRemoved(String name)
                     throws FormulaException
check whether it is safe to remove a variable from the database

Throws:
FormulaException

exists

public boolean exists(String name)
check whether a given variable is currently in the database


remove

public void remove(String name)
            throws FormulaException
remove a variable from the database

Throws:
FormulaException

setThing

public void setThing(String name,
                     Thing t)
              throws VisADException,
                     RemoteException
set a variable's value directly

Throws:
VisADException
RemoteException

setReference

public void setReference(String name,
                         ThingReference tr)
                  throws VisADException
set a variable's ThingReference

Throws:
VisADException

getThing

public Thing getThing(String name)
               throws FormulaException
get a variable's current value

Throws:
FormulaException

getReference

public ThingReference getReference(String name)
                            throws FormulaException
get a variable's associated ThingReference

Throws:
FormulaException

getFormula

public String getFormula(String name)
                  throws FormulaException
get a variable's current formula

Throws:
FormulaException

getVarByName

FormulaVar getVarByName(String name)
                  throws FormulaException
return the variable "name"

Throws:
FormulaException

getVarByNameOrCreate

FormulaVar getVarByNameOrCreate(String name)
                          throws VisADException
return the variable "name", creating it if necessary

Throws:
VisADException

isUnaryOp

boolean isUnaryOp(String op)
identify whether a given token is a unary operator


isBinaryOp

boolean isBinaryOp(String op)
identify whether a given token is a binary operator


isFunction

boolean isFunction(String token)
identify whether a given token is a defined function


getUnaryPrec

int getUnaryPrec(String op)
returns a unary operator's level of precedence


getBinaryPrec

int getBinaryPrec(String op)
returns a binary operator's level of precedence