Class RandomNumberExpression

  • All Implemented Interfaces:
    adams.core.Destroyable, adams.core.GlobalInfoSupporter, adams.core.logging.LoggingLevelHandler, adams.core.logging.LoggingSupporter, adams.core.option.OptionHandler, adams.core.QuickInfoSupporter, adams.core.ShallowCopySupporter<adams.flow.condition.bool.BooleanCondition>, adams.core.SizeOfHandler, adams.core.Stoppable, adams.flow.condition.bool.BooleanCondition, adams.parser.GrammarSupplier, Serializable

    public class RandomNumberExpression
    extends adams.flow.condition.bool.AbstractExpression
    Evaluates to 'true' if the expression evaluates to 'true'.
    The 'X' in the expression is the number generated by the random number generator.

    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) )

    # arithmetics
    | expr + expr
    | expr - expr
    | expr * expr
    | expr / expr
    | expr ^ expr (power of)
    | expr % expr (modulo)
    ;

    # numeric functions
    | abs ( expr )
    | sqrt ( expr )
    | log ( expr )
    | exp ( expr )
    | sin ( expr )
    | cos ( expr )
    | tan ( expr )
    | rint ( expr )
    | floor ( expr )
    | pow[er] ( expr , expr )
    | ceil ( expr )
    | 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] )
    ;

    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 '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


    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
     
    -expression <adams.parser.BooleanExpressionText> (property: expression)
        The expression to evaluate using the current random number obtained from 
        the generator; 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: X < 500
     
    -generator <adams.data.random.RandomNumberGenerator> (property: generator)
        The generator that generates a new random number each time a token arrives.
        default: adams.data.random.JavaRandomInt
     
    Version:
    $Revision$
    Author:
    fracpete (fracpete at waikato dot ac dot nz)
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected adams.data.random.RandomNumberGenerator m_Generator
      the random number generator.
      • 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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void defineOptions()
      Adds options to the internal list of options.
      protected boolean doEvaluate​(adams.flow.core.Actor owner, adams.flow.core.Token token)
      Evaluates the expression.
      String expressionTipText()
      Returns the tip text for this property.
      String generatorTipText()
      Returns the tip text for this property.
      protected adams.parser.BooleanExpressionText getDefaultExpression()
      Returns the default expression to use.
      adams.data.random.RandomNumberGenerator getGenerator()
      Returns the random number generator in use.
      String getQuickInfo()
      Returns the quick info string to be displayed in the flow editor.
      String globalInfo()
      Returns a string describing the object.
      void setGenerator​(adams.data.random.RandomNumberGenerator value)
      Sets the random number generator to use.
      • Methods inherited from class adams.flow.condition.bool.AbstractExpression

        accepts, doEvaluate, getExpression, getGrammar, 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 interface adams.core.logging.LoggingLevelHandler

        getLoggingLevel
    • Field Detail

      • m_Generator

        protected adams.data.random.RandomNumberGenerator m_Generator
        the random number generator.
    • Constructor Detail

      • RandomNumberExpression

        public RandomNumberExpression()
    • Method Detail

      • globalInfo

        public String globalInfo()
        Returns a string describing the object.
        Specified by:
        globalInfo in interface adams.core.GlobalInfoSupporter
        Specified by:
        globalInfo in class adams.core.option.AbstractOptionHandler
        Returns:
        a description suitable for displaying in the gui
      • defineOptions

        public void defineOptions()
        Adds options to the internal list of options.
        Specified by:
        defineOptions in interface adams.core.option.OptionHandler
        Overrides:
        defineOptions in class adams.flow.condition.bool.AbstractExpression
      • getQuickInfo

        public String getQuickInfo()
        Returns the quick info string to be displayed in the flow editor.
        Specified by:
        getQuickInfo in interface adams.flow.condition.bool.BooleanCondition
        Specified by:
        getQuickInfo in interface adams.core.QuickInfoSupporter
        Overrides:
        getQuickInfo in class adams.flow.condition.bool.AbstractExpression
        Returns:
        the info or null if no info to be displayed
      • getDefaultExpression

        protected adams.parser.BooleanExpressionText getDefaultExpression()
        Returns the default expression to use.
        Specified by:
        getDefaultExpression in class adams.flow.condition.bool.AbstractExpression
        Returns:
        the default
      • expressionTipText

        public String expressionTipText()
        Returns the tip text for this property.
        Specified by:
        expressionTipText in class adams.flow.condition.bool.AbstractExpression
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • setGenerator

        public void setGenerator​(adams.data.random.RandomNumberGenerator value)
        Sets the random number generator to use.
        Parameters:
        value - the generator
      • getGenerator

        public adams.data.random.RandomNumberGenerator getGenerator()
        Returns the random number generator in use.
        Returns:
        the generator
      • generatorTipText

        public String generatorTipText()
        Returns the tip text for this property.
        Returns:
        tip text for this property suitable for displaying in the GUI or for listing the options.
      • doEvaluate

        protected boolean doEvaluate​(adams.flow.core.Actor owner,
                                     adams.flow.core.Token token)
        Evaluates the expression.
        Specified by:
        doEvaluate in class adams.flow.condition.bool.AbstractBooleanCondition
        Parameters:
        owner - the owning actor
        token - the current token passing through
        Returns:
        true if the expression evaluates to 'true'