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
        Returns:
        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
        Parameters:
        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
        Returns:
        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
        Parameters:
        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
        Parameters:
        enabled - true if Logix should be enabled; false otherwise
        evt - event to trigger if true
        Returns:
        the new state
      • wantsToTrigger

        boolean wantsToTrigger​(java.beans.PropertyChangeEvent evt)
        Check if an event will trigger actions.
        Parameters:
        evt - the event that possibly triggers actions
        Returns:
        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
        Parameters:
        ant - the antecedent string description
        variableList - arraylist of existing Conditional variables
        Returns:
        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.

        Parameters:
        s - The expression to be parsed
        variableList - ConditionalVariables for R1, R2, etc
        Returns:
        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.
        Throws:
        JmriException - if unable to compute the logic
      • getIntegerValue

        int getIntegerValue​(ConditionalAction action)
        Get an integer from either a String literal or named memory reference.
        Parameters:
        action - an action containing either an integer or name of a Memory
        Returns:
        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.
        Parameters:
        action - an action containing either a number of seconds or name of a Memory
        Returns:
        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
        Parameters:
        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
        Parameters:
        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
        Parameters:
        state - the new state