Class DefaultConditional

    • Constructor Detail

      • DefaultConditional

        public DefaultConditional​(java.lang.String systemName,
                                  java.lang.String userName)
    • Method Detail

      • getBeanType

        public java.lang.String getBeanType()
        Description copied from interface: NamedBean
        For instances in the code where we are dealing with just a bean and a message needs to be passed to the user or in a log.
        Specified by:
        getBeanType in interface NamedBean
        a string of the bean type, eg Turnout, Sensor etc
      • getIndexInTable

        public static int getIndexInTable​(int[] table,
                                          int entry)
      • setLogicType

        public void setLogicType​(Conditional.AntecedentOperator type,
                                 java.lang.String antecedent)
        Set the logic type (all AND's all OR's or mixed AND's and OR's set the antecedent expression - should be a well formed boolean statement with parenthesis indicating the order of evaluation)
        Specified by:
        setLogicType in interface Conditional
        type - index of the logic type
        antecedent - non-localized (US-english) string description of antecedent
      • getTriggerOnChange

        public boolean getTriggerOnChange()
        Specified by:
        getTriggerOnChange in interface Conditional
        true if action list is executed only when state changes, false if action list is executed on every calculation of state
      • setStateVariables

        public void setStateVariables​(java.util.List<ConditionalVariable> arrayList)
        Set State Variables for this Conditional. Each state variable will evaluate either True or False when this Conditional is calculated.

        This method assumes that all information has been validated.

        Specified by:
        setStateVariables in interface Conditional
        arrayList - the list of variables
      • calculate

        public int calculate​(boolean enabled,
                             java.beans.PropertyChangeEvent evt)
        Calculate this Conditional. When _enabled is false, Conditional.calculate will compute the state of the conditional, but will not trigger its actions. When _enabled is true, the state is computed and if the state has changed, will trigger all its actions.
        Specified by:
        calculate in interface Conditional
        enabled - true if Logix should be enabled; false otherwise
        evt - event to trigger if true
        the new state
      • wantsToTrigger

        boolean wantsToTrigger​(java.beans.PropertyChangeEvent evt)
        Check if an event will trigger actions.
        evt - the event that possibly triggers actions
        true if event will trigger actions; false otherwise
      • validateAntecedent

        public java.lang.String validateAntecedent​(java.lang.String ant,
                                                   java.util.List<ConditionalVariable> variableList)
        Check that an antecedent is well formed.
        Specified by:
        validateAntecedent in interface Conditional
        ant - the antecedent string description
        variableList - arraylist of existing Conditional variables
        error message string if not well formed
      • parseCalculate

        DefaultConditional.DataPair parseCalculate​(java.lang.String s,
                                                   java.util.List<ConditionalVariable> variableList)
                                            throws JmriException
        Parses and computes one parenthesis level of a boolean statement.

        Recursively calls inner parentheses levels. Note that all logic operators are detected by the parsing, therefore the internal negation of a variable is washed.

        s - The expression to be parsed
        variableList - ConditionalVariables for R1, R2, etc
        a data pair consisting of the truth value of the level a count of the indices consumed to parse the level and a bitmap of the variable indices used.
        JmriException - if unable to compute the logic
      • getIntegerValue

        int getIntegerValue​(ConditionalAction action)
        Get an integer from either a String literal or named memory reference.
        action - an action containing either an integer or name of a Memory
        the integral value of the action or -1 if the action references a Memory that does not contain an integral value
      • getMillisecondValue

        int getMillisecondValue​(ConditionalAction action)
        Get the number of milliseconds from either a String literal or named memory reference containing a value representing a number of seconds.
        action - an action containing either a number of seconds or name of a Memory
        the number of milliseconds represented by action of -1 if action references a Memory without a numeric value
      • cancelSensorTimer

        public void cancelSensorTimer​(java.lang.String sname)
        Stop a sensor timer if one is actively delaying setting of the specified sensor
        Specified by:
        cancelSensorTimer in interface Conditional
        sname - the name of the timer
      • cancelTurnoutTimer

        public void cancelTurnoutTimer​(java.lang.String sname)
        Stop a turnout timer if one is actively delaying setting of the specified turnout
        Specified by:
        cancelTurnoutTimer in interface Conditional
        sname - the name of the timer
      • setState

        public void setState​(int state)
        State of Conditional is set. Not really public for Conditionals. The state of a Conditional is only changed by its calculate method, so the state is really a read-only bound property.
        Specified by:
        setState in interface NamedBean
        state - the new state