Package adams.flow.condition.bool
Class Expression
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,QuickInfoSupporter
,ShallowCopySupporter<BooleanCondition>
,SizeOfHandler
,Stoppable
,BooleanCondition
,GrammarSupplier
,Serializable
public class Expression extends AbstractExpression
Evaluates to 'true' if the expression evaluates to 'true'.
In case of java.lang.Number tokens that arrive at the input, these can be accessed in the expression via 'X'; string tokens can be accessed via expression '"X"' (surrounding double quotes are required).
If the incoming token is either a Report or a ReportHandler, the contents of the report get added as values as well (boolean, numeric or string) and you can access them via their name instead of 'X'.
The following grammar is used for evaluating the boolean expressions:
expr_list ::= '=' expr_list expr_part | expr_part ;
expr_part ::= expr ;
expr ::= ( expr )
# data types
| number
| string
| boolean
| date
# constants
| true
| false
| pi
| e
| now()
| today()
# negating numeric value
| -expr
# comparisons
| expr < expr
| expr <= expr
| expr > expr
| expr >= expr
| expr = expr
| expr != expr (or: expr <> expr)
# boolean operations
| ! expr (or: not expr)
| expr & expr (or: expr and expr)
| expr | expr (or: expr or expr)
| if[else] ( expr , expr (if true) , expr (if false) )
| ifmissing ( variable , expr (default value if variable is missing) )
| isNaN ( expr )
# arithmetics
| expr + expr
| expr - expr
| expr * expr
| expr / expr
| expr ^ expr (power of)
| expr % expr (modulo)
;
# numeric functions
| abs ( expr )
| sqrt ( expr )
| cbrt ( expr )
| log ( expr )
| log10 ( expr )
| exp ( expr )
| sin ( expr )
| sinh ( expr )
| cos ( expr )
| cosh ( expr )
| tan ( expr )
| tanh ( expr )
| atan ( expr )
| atan2 ( exprY , exprX )
| hypot ( exprX , exprY )
| signum ( expr )
| rint ( expr )
| floor ( expr )
| pow[er] ( expr , expr )
| ceil ( expr )
| min ( expr1 , expr2 )
| max ( expr1 , expr2 )
| year ( expr )
| month ( expr )
| day ( expr )
| hour ( expr )
| minute ( expr )
| second ( expr )
| weekday ( expr )
| weeknum ( expr )
# string functions
| substr ( expr , start [, end] )
| left ( expr , len )
| mid ( expr , start , len )
| right ( expr , len )
| rept ( expr , count )
| concatenate ( expr1 , expr2 [, expr3-5] )
| lower[case] ( expr )
| upper[case] ( expr )
| trim ( expr )
| matches ( expr , regexp )
| trim ( expr )
| len[gth] ( str )
| find ( search , expr [, pos] )
| replace ( str , pos , len , newstr )
| substitute ( str , find , replace [, occurrences] )
# array functions
| len[gth] ( array )
| get ( array , index )
;
Notes:
- Variables are either all upper case letters (e.g., "ABC") or any character apart from "]" enclosed by "[" and "]" (e.g., "[Hello World]").
- 'start' and 'end' for function 'substr' are indices that start at 1.
- 'index' for function 'get' starts at 1.
- Index 'end' for function 'substr' is excluded (like Java's 'String.substring(int,int)' method)
- Line comments start with '#'
- Semi-colons (';') or commas (',') can be used as separator in the formulas,
e.g., 'pow(2,2)' is equivalent to 'pow(2;2)'
- dates have to be of format 'yyyy-MM-dd' or 'yyyy-MM-dd HH:mm:ss'
- times have to be of format 'HH:mm:ss' or 'yyyy-MM-dd HH:mm:ss'
- the characters in square brackets in function names are optional:
e.g. 'len("abc")' is the same as 'length("abc")'
A lot of the functions have been modeled after LibreOffice:
https://help.libreoffice.org/Calc/Functions_by_Category
Additional functions:
- env(String): String
First argument is the name of the environment variable to retrieve.
The result is the value of the environment variable.
Additional procedures:
- println(...)
One or more arguments are printed as comma-separated list to stdout.
If no argument is provided, a simple line feed is output.
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-expression <adams.parser.BooleanExpressionText> (property: expression) The expression to evaluate; expressions that consists solely of a variable (eg '@{blah}') get automatically wrapped in parentheses, since the expression string gets interpreted as attached variable instead. default: true
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class adams.flow.condition.bool.AbstractExpression
m_Expression
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
-
Constructor Summary
Constructors Constructor Description Expression()
Default constructor.Expression(BooleanExpressionText expression)
Initializes with the specified expression.Expression(String expression)
Initializes with the specified expression.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected boolean
doEvaluate(Actor owner, Token token)
Evaluates the expression.String
expressionTipText()
Returns the tip text for this property.protected BooleanExpressionText
getDefaultExpression()
Returns the default expression to use.String
globalInfo()
Returns a string describing the object.-
Methods inherited from class adams.flow.condition.bool.AbstractExpression
accepts, defineOptions, doEvaluate, getExpression, getGrammar, getQuickInfo, setExpression, setExpression, setUp
-
Methods inherited from class adams.flow.condition.bool.AbstractBooleanCondition
evaluate, preEvaluate, shallowCopy, shallowCopy, stopExecution
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, destroy, finishInit, getDefaultLoggingLevel, getOptionManager, initialize, loggingLevelTipText, newOptionManager, reset, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, sizeOf
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel
-
-
-
-
Constructor Detail
-
Expression
public Expression()
Default constructor.
-
Expression
public Expression(BooleanExpressionText expression)
Initializes with the specified expression.- Parameters:
expression
- the expression to use
-
Expression
public Expression(String expression)
Initializes with the specified expression.- Parameters:
expression
- the expression to use
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
getDefaultExpression
protected BooleanExpressionText getDefaultExpression()
Returns the default expression to use.- Specified by:
getDefaultExpression
in classAbstractExpression
- Returns:
- the default
-
expressionTipText
public String expressionTipText()
Returns the tip text for this property.- Specified by:
expressionTipText
in classAbstractExpression
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
doEvaluate
protected boolean doEvaluate(Actor owner, Token token)
Evaluates the expression.- Specified by:
doEvaluate
in classAbstractBooleanCondition
- Parameters:
owner
- the owning actortoken
- the current token passing through- Returns:
- true if the expression evaluates to 'true'
-
-