Class DefaultConditional

java.lang.Object
jmri.implementation.AbstractNamedBean
jmri.implementation.DefaultConditional
All Implemented Interfaces:
Comparable<NamedBean>, PropertyChangeProvider, Conditional, NamedBean
Direct Known Subclasses:
SensorGroupConditional

public class DefaultConditional extends AbstractNamedBean implements Conditional
Class providing the basic logic of the Conditional interface.
  • Field Details

  • Constructor Details

  • Method Details

    • getBeanType

      public 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)
    • getAntecedentExpression

      Get antecedent (boolean string expression) of Conditional.
      Specified by:
      getAntecedentExpression in interface Conditional
      Returns:
      the expression
    • getLogicType

      Get type of operators in the antecedent statement.
      Specified by:
      getLogicType in interface Conditional
      Returns:
      the type
    • setLogicType

      public void setLogicType(Conditional.AntecedentOperator type, 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
    • setTriggerOnChange

      public void setTriggerOnChange(boolean trigger)
      Description copied from interface: Conditional
      Set policy for execution of action list
      Specified by:
      setTriggerOnChange in interface Conditional
      Parameters:
      trigger - true execute only on change of state
    • setStateVariables

      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
    • getCopyOfStateVariables

      Make deep clone of variables.
      Specified by:
      getCopyOfStateVariables in interface Conditional
      Returns:
      a list containing copies of variables
    • getStateVariableList

      Get the list of state variables for this Conditional.
      Returns:
      the list of state variables
    • setAction

      public void setAction(@Nonnull List<ConditionalAction> arrayList)
      Set list of actions.
      Specified by:
      setAction in interface Conditional
      Parameters:
      arrayList - the actions
    • getCopyOfActions

      Make deep clone of actions.
      Specified by:
      getCopyOfActions in interface Conditional
      Returns:
      a list of copies of actions
    • getActionList

      Get the list of actions for this conditional.
      Returns:
      the list of actions
    • calculate

      public int calculate(boolean enable, 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:
      enable - true to enable, else false.
      evt - event to trigger if true
      Returns:
      the new state
    • wantsToTrigger

      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

      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

      jmri.implementation.DefaultConditional.DataPair parseCalculate(String expression, 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:
      expression - 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

      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

      Get the number of milliseconds from either a String literal or named memory reference containing a value representing a number of seconds.

      The String is not I18N and should use a . decimal seperater.

      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(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(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
    • getState

      public int getState()
      State of the Conditional is returned.
      Specified by:
      getState in interface Conditional
      Specified by:
      getState in interface NamedBean
      Returns:
      state value
    • 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
    • dispose

      public void dispose()
      Dispose this DefaultConditional.
      Specified by:
      dispose in interface Conditional
      Specified by:
      dispose in interface NamedBean
      Overrides:
      dispose in class AbstractNamedBean