Package adams.parser
Class BaseTimeMsecExpression
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.parser.AbstractExpressionEvaluator<Date>
-
- adams.parser.BaseTimeMsecExpression
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,GrammarSupplier
,Serializable
public class BaseTimeMsecExpression extends AbstractExpressionEvaluator<Date> implements GrammarSupplier
Evaluates time expressions.
Format:
(<date>|NOW|-INF|+INF|START|END) [expr (SECOND|MINUTE|HOUR)]*
expr ::= ( expr )
| - expr
| + expr
| expr + expr
| expr - expr
| expr * expr
| expr / expr
| expr % expr
| expr ^ expr
| abs ( expr )
| sqrt ( expr )
| log ( expr )
| exp ( expr )
| rint ( expr )
| floor ( expr )
| pow[er] ( expr , expr )
| ceil ( expr )
| NUMBER
Examples:
01:02:03
01:02:03 +1 MINUTE
NOW
+INF
NOW +1 HOUR
NOW +14 MINUTE
NOW +(2*3) MINUTE
Amounts can be chained as well:
NOW -1 MINUTE +1 HOUR
START and END can only be set programmatically; by default they are equal to -INF and +INF.
Valid options are:
-logging-level <OFF|SEVERE|WARNING|INFO|CONFIG|FINE|FINER|FINEST> (property: loggingLevel) The logging level for outputting errors and debugging output. default: WARNING
-env <java.lang.String> (property: environment) The class to use for determining the environment. default: adams.env.Environment
-expression <java.lang.String> (property: expression) The boolean expression to evaluate (must evaluate to a boolean). default: NOW
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class adams.parser.AbstractExpressionEvaluator
m_Environment, 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 BaseTimeMsecExpression()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Date
evaluate()
Performs the evaluation.static Date
evaluate(String expr)
Parses and evaluates the given expression.static Date
evaluate(String expr, Date start, Date end)
Parses and evaluates the given expression.Date
evaluate(Date start, Date end)
Performs the evaluation.String
expressionTipText()
Returns the tip text for this property.protected String
getDefaultExpression()
Returns the default expression to use.String
getGrammar()
Returns a string representation of the grammar.String
globalInfo()
Returns a string describing the object.protected Object
initializeSymbol(String name, String value)
Initializes the symbol.static void
main(String[] args)
Runs the evaluator from command-line.-
Methods inherited from class adams.parser.AbstractExpressionEvaluator
defineOptions, environmentTipText, forCommandLine, forName, getEnvironment, getExpression, runEvaluator, setEnvironment, setExpression
-
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
-
-
-
-
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
-
getGrammar
public String getGrammar()
Returns a string representation of the grammar.- Specified by:
getGrammar
in interfaceGrammarSupplier
- Returns:
- the grammar, null if not available
-
getDefaultExpression
protected String getDefaultExpression()
Returns the default expression to use.- Specified by:
getDefaultExpression
in classAbstractExpressionEvaluator<Date>
- Returns:
- the default expression
-
expressionTipText
public String expressionTipText()
Returns the tip text for this property.- Specified by:
expressionTipText
in classAbstractExpressionEvaluator<Date>
- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
initializeSymbol
protected Object initializeSymbol(String name, String value)
Initializes the symbol.- Parameters:
name
- the name of the symbolvalue
- the string representation of the symbol- Returns:
- the object representation of the symbol
-
evaluate
public Date evaluate() throws Exception
Performs the evaluation.- Specified by:
evaluate
in classAbstractExpressionEvaluator<Date>
- Returns:
- the evaluation, or null in case of error
- Throws:
Exception
- if evaluation fails
-
evaluate
public Date evaluate(Date start, Date end) throws Exception
Performs the evaluation.- Parameters:
start
- the start time, can be nullend
- the end time, can be null- Returns:
- the evaluation, or null in case of error
- Throws:
Exception
- if evaluation fails
-
evaluate
public static Date evaluate(String expr) throws Exception
Parses and evaluates the given expression. Returns the result of the boolean expression, based on the given values of the symbols.- Parameters:
expr
- the expression to evaluate- Returns:
- the evaluated result
- Throws:
Exception
- if something goes wrong
-
evaluate
public static Date evaluate(String expr, Date start, Date end) throws Exception
Parses and evaluates the given expression. Returns the result of the boolean expression, based on the given values of the symbols.- Parameters:
expr
- the expression to evaluatestart
- the start time, can be nullend
- the end time, can be null- Returns:
- the evaluated result
- Throws:
Exception
- if something goes wrong- See Also:
BaseTimeMsec.START
,BaseTimeMsec.END
-
main
public static void main(String[] args)
Runs the evaluator from command-line.- Parameters:
args
- the command-line options, use "-help" to list them
-
-