Package adams.parser

Class BaseTimeExpression

  • All Implemented Interfaces:
    Destroyable, GlobalInfoSupporter, LoggingLevelHandler, LoggingSupporter, OptionHandler, SizeOfHandler, GrammarSupplier, Serializable

    public class BaseTimeExpression
    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
     
    Version:
    $Revision$
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Constructor Detail

      • BaseTimeExpression

        public BaseTimeExpression()
    • Method Detail

      • getGrammar

        public String getGrammar()
        Returns a string representation of the grammar.
        Specified by:
        getGrammar in interface GrammarSupplier
        Returns:
        the grammar, null if not available
      • expressionTipText

        public String expressionTipText()
        Returns the tip text for this property.
        Specified by:
        expressionTipText in class AbstractExpressionEvaluator<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 symbol
        value - the string representation of the symbol
        Returns:
        the object representation of the symbol
      • evaluate

        public Date evaluate​(Date start,
                             Date end)
                      throws Exception
        Performs the evaluation.
        Parameters:
        start - the start time, can be null
        end - 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 evaluate
        start - the start time, can be null
        end - the end time, can be null
        Returns:
        the evaluated result
        Throws:
        Exception - if something goes wrong
        See Also:
        BaseTime.START, BaseTime.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