Package adams.parser
Class BaseDateTimeMsecExpression
- java.lang.Object
-
- adams.core.logging.LoggingObject
-
- adams.core.logging.CustomLoggingLevelObject
-
- adams.core.option.AbstractOptionHandler
-
- adams.parser.AbstractExpressionEvaluator<Date>
-
- adams.parser.BaseDateTimeMsecExpression
-
- All Implemented Interfaces:
Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,SizeOfHandler
,GrammarSupplier
,Serializable
public class BaseDateTimeMsecExpression extends AbstractExpressionEvaluator<Date> implements GrammarSupplier
Evaluates date/time (with msec) expressions.
Format:
(<date>|NOW|TODAY|TOMORROW|YESTERDAY|-INF|+INF|START|END) [expr (MILLISECOND|SECOND|MINUTE|HOUR|DAY|BUSINESSDAY|WEEK|MONTH|YEAR)]*
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
Note:
TODAY/TOMORROW/YESTERDAY generate a date at the start of the day.
Examples:
1999-12-31 01:02:03.123
1999-12-31 01:02:03.123 +1 MINUTE
NOW
+INF
NOW +1 YEAR
NOW +14 DAY
NOW +(2*3) DAY
Amounts can be chained as well:
NOW -1 MONTH +1 DAY
START and END can only be set programmatically; by default they are equal to -INF and +INF.
-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
-business-days <MONDAY_TO_FRIDAY|MONDAY_TO_SATURDAY|SATURDAY_TO_THURSDAY|SUNDAY_TO_THURSDAY|SUNDAY_TO_FRIDAY> (property: businessDays) How to interpret business days. default: MONDAY_TO_FRIDAY
- Author:
- FracPete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected BusinessDays
m_BusinessDays
how to interpret business days.-
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 BaseDateTimeMsecExpression()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
businessDaysTipText()
Returns the tip text for this property.void
defineOptions()
Adds options to the internal list of options.Date
evaluate()
Performs the evaluation.static Date
evaluate(String expr, Date start, Date end, BusinessDays bdays)
Parses and evaluates the given expression.Date
evaluate(Date start, Date end)
Performs the evaluation.String
expressionTipText()
Returns the tip text for this property.BusinessDays
getBusinessDays()
Returns what business days to use.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.void
setBusinessDays(BusinessDays value)
Sets what business days to use.-
Methods inherited from class adams.parser.AbstractExpressionEvaluator
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
-
-
-
-
Field Detail
-
m_BusinessDays
protected BusinessDays m_BusinessDays
how to interpret business days.
-
-
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
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractExpressionEvaluator<Date>
-
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.
-
setBusinessDays
public void setBusinessDays(BusinessDays value)
Sets what business days to use.- Parameters:
value
- the type
-
getBusinessDays
public BusinessDays getBusinessDays()
Returns what business days to use.- Returns:
- the type
-
businessDaysTipText
public String businessDaysTipText()
Returns the tip text for this property.- 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 datetime, can be nullend
- the end datetime, can be null- Returns:
- the evaluation, or null in case of error
- Throws:
Exception
- if evaluation fails
-
evaluate
public static Date evaluate(String expr, Date start, Date end, BusinessDays bdays) 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 datetime, can be nullend
- the end datetime, can be nullbdays
- how to interpret business days- Returns:
- the evaluated result
- Throws:
Exception
- if something goes wrong- See Also:
BaseDateTimeMsec.START
,BaseDateTimeMsec.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
-
-