org.safs.SafsExpression
Class SafsExpression

java.lang.Object
  |
  +--org.safs.SafsExpression.SafsExpression

public class SafsExpression
extends java.lang.Object


Field Summary
protected  boolean booErrors
           
protected  boolean debugPrint
           
protected  java.util.Hashtable hSafsVars
           
protected  int iExpressionlength
           
protected  int numDecimalPlaces
           
protected  java.lang.String sExpression
           
protected  java.lang.String strErrors
           
protected  boolean stripLeadZero
           
protected  boolean stripTrailingDecimalPoint
           
protected  boolean stripTrailingZeros
           
protected  java.util.Vector vQuoteLocs
           
protected  java.util.Vector vSubStrings
           
protected  java.util.Vector vVariableNames
           
 
Constructor Summary
SafsExpression(java.lang.String sText)
          Method SafsExpression.
 
Method Summary
protected  java.lang.String dereferenceVariable(java.lang.String strText)
          Method dereferenceVariable.
 java.lang.String evalExpression()
          Method evalExpression.
protected  java.lang.String evalExpression(java.lang.String strExpr)
          Method evalExpression.
protected  java.lang.String evalPrimative(java.lang.String strLeftOperand, java.lang.String strOperator, java.lang.String strRightOperand)
          Method evalPrimative.
protected  java.lang.String evalSimple(java.lang.String strExpr)
          Method evalSimple.
 java.lang.String getExpression()
          Method getExpression.
protected  java.lang.String getLeftOperand(java.lang.String strExpr, int iOperatorLoc)
          Method getLeftOperand.
 java.util.Vector getQuoteLocs()
          Method getQuoteLocs.
protected  java.lang.String getRightOperand(java.lang.String strExpr, int iOperatorLoc)
          Method getRightOperand.
 java.util.Vector getSubStrings()
          Method getSubStrings.
 java.util.Hashtable getVarHash()
           
 java.util.Vector getVariableNames()
          Method getVariableNames.
protected  java.lang.String getVarValue(java.lang.String strVarName)
          Method getVarValue.
protected  java.lang.String handleOperators(java.lang.String strExpr, java.lang.String strOps)
          Method handleOperators.
protected  void initData(java.lang.String sText)
          Method initData.
 int numDecimalPlaces()
          Method numDecimalPlaces.
 void numDecimalPlaces(int i)
          Method numDecimalPlaces.
 void setExpression(java.lang.String sText)
          Method setExpression.
 void setVarHash(java.util.Hashtable h)
           
protected  void setVariableNames()
          Method setVariableNames.
protected  void setVarValue(java.lang.String strVarName, java.lang.String strVarValue)
          Method setVarValue.
 boolean stripLeadZero()
          Method stripLeadZero.
 void stripLeadZero(boolean b)
          Method stripLeadZero.
 boolean stripTrailingDecimalPoint()
          Method stripTrailingDecimalPoint.
 void stripTrailingDecimalPoint(boolean b)
          Method stripTrailingDecimalPoint.
 boolean stripTrailingZeros()
          Method stripTrailingZeros.
 void stripTrailingZeros(boolean b)
          Method stripTrailingZeros.
protected  boolean validateParens()
          Method validateParens.
protected  void validateVariableNames()
          Method validateVariableNames.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sExpression

protected java.lang.String sExpression

iExpressionlength

protected int iExpressionlength

vQuoteLocs

protected java.util.Vector vQuoteLocs

vSubStrings

protected java.util.Vector vSubStrings

vVariableNames

protected java.util.Vector vVariableNames

strErrors

protected java.lang.String strErrors

booErrors

protected boolean booErrors

debugPrint

protected boolean debugPrint

stripLeadZero

protected boolean stripLeadZero

stripTrailingZeros

protected boolean stripTrailingZeros

stripTrailingDecimalPoint

protected boolean stripTrailingDecimalPoint

numDecimalPlaces

protected int numDecimalPlaces

hSafsVars

protected java.util.Hashtable hSafsVars
Constructor Detail

SafsExpression

public SafsExpression(java.lang.String sText)
               throws java.lang.Exception
Method SafsExpression.
Parameters:
sText - The SAFS string expression
Throws:
java.lang.Exception - Error messages such as unmatched parentheses or illegal variable names
Method Detail

setExpression

public void setExpression(java.lang.String sText)
                   throws java.lang.Exception
Method setExpression. Sets the SAFS expression to a new value and initializes internals
Parameters:
sText - The SAFS string expression
Throws:
java.lang.Exception - Error messages such as unmatched parentheses or illegal variable names

getExpression

public java.lang.String getExpression()
Method getExpression. Accessor for the protected field sExpression
Returns:
String The SAFS expression

getQuoteLocs

public java.util.Vector getQuoteLocs()
Method getQuoteLocs. Accessor for the protected field vQuoteLocs
Returns:
Vector Integer objects containing locations of the quotes (if any)

getSubStrings

public java.util.Vector getSubStrings()
Method getSubStrings. Accessor for the protected field vSubStrings
Returns:
Vector String objects containing quoted substrings of the expression (if any)

getVariableNames

public java.util.Vector getVariableNames()
Method getVariableNames. Accessor for the protected field vVariableNames
Returns:
Vector String objects that are the variables found within the expression sExpression

stripLeadZero

public void stripLeadZero(boolean b)
Method stripLeadZero. Setter for the protected field stripLeadZero

sets option to strip the leading zero from expression results. For example, if the expression evaluates to 0.1 and stripLeadZero is true, the result will be formatted such that the leading zero is not shown, which would be .1

Parameters:
b - true or false specifying wheather or not leading zeros should be stripped

stripLeadZero

public boolean stripLeadZero()
Method stripLeadZero. Accessor for the protected field stripLeadZero
Returns:
boolean The current specified option to strip leading zeros

stripTrailingZeros

public void stripTrailingZeros(boolean b)
Method stripTrailingZeros. Setter for the protected field stripTrailingZeros

sets option to strip the trailing zeros from expression results. For example, if the expression evaluates to 1.100 and stripTrailingZeros is true, the result will be formatted such that the trailing zeros are not shown, which would be 1.1

Parameters:
b - true or false specifying wheather or not trailing zeros should be stripped

stripTrailingZeros

public boolean stripTrailingZeros()
Method stripTrailingZeros. Accessor for the protected field stripTrailingZeros
Returns:
boolean The current specified option to strip trailing zeros

stripTrailingDecimalPoint

public void stripTrailingDecimalPoint(boolean b)
Method stripTrailingDecimalPoint. Setter for the protected field stripTrailingDecimalPoint

sets option to strip the trailing decimal points from expression results. For example, if the expression evaluates to 1. and stripTrailingDecimalPoint is true, the result will be formatted such that the trailing zeros are not shown, which would be 1

Parameters:
b - true or false specifying wheather or not trailing decimal points should be stripped

stripTrailingDecimalPoint

public boolean stripTrailingDecimalPoint()
Method stripTrailingDecimalPoint. Accessor for the protected field stripTrailingDecimalPoint
Returns:
boolean The current specified option to strip trailing decimal point

numDecimalPlaces

public void numDecimalPlaces(int i)
Method numDecimalPlaces. Setter for the protected field numDecimalPlaces
Parameters:
i - int specifying the number of decimal places to round half up in division operations

numDecimalPlaces

public int numDecimalPlaces()
Method numDecimalPlaces. Accessor for the protected field numDecimalPlaces
Returns:
int The number of decimal places to round half up in division operations

evalExpression

public java.lang.String evalExpression()
Method evalExpression. This is the method called to evaluate the expression and return the result
Returns:
String The result of evaluating the expression

initData

protected void initData(java.lang.String sText)
                 throws java.lang.Exception
Method initData. Initialize internal data fields and validate the expression
Parameters:
sText - The SAFS string expression
Throws:
java.lang.Exception - Error messages such as unmatched parentheses or illegal variable names

setVariableNames

protected void setVariableNames()
Method setVariableNames. Used to populate the protected field vVariableNames

validateParens

protected boolean validateParens()
Method validateParens. Returns true or false specifying wheather or not the expression has correctly matched parentheses
Returns:
boolean

validateVariableNames

protected void validateVariableNames()
Method validateVariableNames. Make sure the variables within the expression are legally named. Set error string and flag for illegally named variables.

getVarValue

protected java.lang.String getVarValue(java.lang.String strVarName)
Method getVarValue. Retrieve the SAFS variable value
Parameters:
strVarName - The name of the variable to retrieve
Returns:
String The value of the variable

setVarValue

protected void setVarValue(java.lang.String strVarName,
                           java.lang.String strVarValue)
Method setVarValue. Set the specified variable to the specified value
Parameters:
strVarName - The name of the variable to set
strVarValue - The value to set the variable to

evalExpression

protected java.lang.String evalExpression(java.lang.String strExpr)
Method evalExpression. Recursively called with each nested parenthetical expression
Parameters:
strExpr - The expression to evaluate
Returns:
String The result of the evaluation

evalSimple

protected java.lang.String evalSimple(java.lang.String strExpr)
Method evalSimple. A simple expression is one without parentheses
Parameters:
strExpr - The simple expression to evaluate
Returns:
String The simple expression evaluated

handleOperators

protected java.lang.String handleOperators(java.lang.String strExpr,
                                           java.lang.String strOps)
Method handleOperators. The grunt work of handling operators at the same precedence.
Parameters:
strExpr - The expression to evaluate
strOps - The operators to handle at the same precedence. For example "+-&" are evaluated at the same precedence.
Returns:
String The result of the expression evaluation

dereferenceVariable

protected java.lang.String dereferenceVariable(java.lang.String strText)
Method dereferenceVariable. If strText is a variable, return its value
Parameters:
strText - The string to check wich may or may not be a variable
Returns:
String The string strText or the value of the variable if strText is a variable

getRightOperand

protected java.lang.String getRightOperand(java.lang.String strExpr,
                                           int iOperatorLoc)
Method getRightOperand. Using infix notation, the right operand is the string to the right of the operator at iOperatorLoc up to a termination character.
Parameters:
strExpr - The expression
iOperatorLoc - The int location of the operator within strExpr
Returns:
String The right operand

getLeftOperand

protected java.lang.String getLeftOperand(java.lang.String strExpr,
                                          int iOperatorLoc)
Method getLeftOperand. Using infix notation, the left operand is the string to the left of the operator at iOperatorLoc up to a termination character.
Parameters:
strExpr - The expression
iOperatorLoc - The int location of the operator within strExpr
Returns:
String The left operand

evalPrimative

protected java.lang.String evalPrimative(java.lang.String strLeftOperand,
                                         java.lang.String strOperator,
                                         java.lang.String strRightOperand)
Method evalPrimative. Primative means an expression in infix notation as "LeftOperand Operator RightOperand" only
Parameters:
strLeftOperand - The left operand
strOperator - The operator
strRightOperand - The right operand
Returns:
String The result of evaluating "LeftOperand Operator RightOperand"

setVarHash

public void setVarHash(java.util.Hashtable h)

getVarHash

public java.util.Hashtable getVarHash()