lt.monarch.math
Class LogicalParser

java.lang.Object
  extended by lt.monarch.math.AbstractFormulaParser
      extended by lt.monarch.math.LogicalParser
All Implemented Interfaces:
java.io.Serializable

public class LogicalParser
extends AbstractFormulaParser

Logical parser, which parses boolean expressions. You must supply the string, which would return true or false result. e.g. "x0>5" or "(sin(x0) <= 1) && (sin(x0) >= -1). Notice that if you use conjunction or union for expressions which are not trivial (true, false values), it is better to use the brackets to specify the boundaries, which parts must be united or conjuncted. Any formula, which is possible to parse with FormulaParser, can be used in this expression. Also boolean values "true", "false" are allowed too. If you prefer you can use ".T",".F" instead of true, false. Allowed operations in the expression are:

&& - conjunction operator

|| - union operator

## - xor operator

! - negation operator

<, >, ==, !=, <=, >= are comparison operators

(,) - brackets can be used to specify the boundaries of union, negation and etc. Be sure to match the number of brackets. All comparison operations has a higher priority over &&, || and ## operations. So if you want those operations to be performed prior to comparison operations, you must use brackets. Any comparison operation, except == and !=, will return false value. Null values can be compared with == and != operators,e.g "x0==null"

See Also:
Serialized Form

Nested Class Summary
Modifier and Type Class and Description
 
Nested classes/interfaces inherited from class lt.monarch.math.AbstractFormulaParser
AbstractFormulaParser.AbstractNode
 
Field Summary
Modifier and Type Field and Description
 
Fields inherited from class lt.monarch.math.AbstractFormulaParser
dataModel, nodeHash
 
Constructor Summary
Constructor and Description
LogicalParser(java.lang.String expression)
          Logical parser constructor.
 
Method Summary
Modifier and Type Method and Description
 void dispose()
          Disposes the resources used by the class
 boolean eval()
          Evaluates the logical expression
 boolean eval(double value)
          Evaluates the logical expression
 boolean eval(java.lang.Double[] variables)
          Evaluates the logical expression
protected  void finalize()
           
 void setDataModel(DataModel dataModel)
          Sets the dataModel object
 void setVariable(java.lang.String variableName, int value)
          Sets variable value
 
Methods inherited from class lt.monarch.math.AbstractFormulaParser
getDataModel
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LogicalParser

public LogicalParser(java.lang.String expression)
              throws java.lang.Exception
Logical parser constructor.

Parameters:
expression - logical expression
Throws:
java.lang.Exception - throws exception if any error occurs, when building evaluation tree or tokenizing the formula.
Method Detail

setDataModel

public void setDataModel(DataModel dataModel)
Description copied from class: AbstractFormulaParser
Sets the dataModel object

Overrides:
setDataModel in class AbstractFormulaParser
Parameters:
dataModel - the dataModel object

setVariable

public void setVariable(java.lang.String variableName,
                        int value)
Sets variable value

Parameters:
variableName - variable name. Possible names: index, row, column
value - variable value

eval

public boolean eval()
Evaluates the logical expression

Returns:
returns boolean value

eval

public boolean eval(double value)
Evaluates the logical expression

Parameters:
value - value to set for x0 variable
Returns:
returns boolean value

eval

public boolean eval(java.lang.Double[] variables)
Evaluates the logical expression

Parameters:
variables - array of x values. The 0th element of array corresponds to x0 variable, 1st to x1 and etc.
Returns:
returns boolean value of the expression

dispose

public void dispose()
Description copied from class: AbstractFormulaParser
Disposes the resources used by the class

Specified by:
dispose in class AbstractFormulaParser

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable