Package jmri.implementation
Class DefaultConditional
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.DefaultConditional
-
- All Implemented Interfaces:
java.lang.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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DefaultConditional.DataPair
(package private) class
DefaultConditional.ErrorDialog
(package private) class
DefaultConditional.TimeSensor
Class for defining ActionListener for ACTION_DELAYED_SENSOR(package private) class
DefaultConditional.TimeTurnout
Class for defining ActionListener for ACTION_DELAYED_TURNOUT-
Nested classes/interfaces inherited from interface jmri.Conditional
Conditional.Action, Conditional.AntecedentOperator, Conditional.ItemType, Conditional.Operator, Conditional.State, Conditional.Type
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<ConditionalAction>
_actionList
(package private) static java.util.ResourceBundle
rbx
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.Conditional
ACTION_ALLOCATE_WARRANT_ROUTE, ACTION_AUTO_RUN_WARRANT, ACTION_CANCEL_SENSOR_TIMERS, ACTION_CANCEL_TURNOUT_TIMERS, ACTION_CLEAR_BLOCK_ERROR, ACTION_CLEAR_SIGNAL_HELD, ACTION_CLEAR_SIGNALMAST_HELD, ACTION_CONTROL_AUDIO, ACTION_CONTROL_TRAIN, ACTION_COPY_MEMORY, ACTION_DEALLOCATE_BLOCK, ACTION_DEALLOCATE_WARRANT_ROUTE, ACTION_DELAYED_SENSOR, ACTION_DELAYED_TURNOUT, ACTION_DISABLE_LOGIX, ACTION_ENABLE_LOGIX, ACTION_GET_BLOCK_TRAIN_NAME, ACTION_GET_BLOCK_WARRANT, ACTION_GET_TRAIN_LOCATION, ACTION_JYTHON_COMMAND, ACTION_LOCK_TURNOUT, ACTION_MANUAL_RUN_WARRANT, ACTION_NONE, ACTION_OPTION_ON_CHANGE, ACTION_OPTION_ON_CHANGE_TO_FALSE, ACTION_OPTION_ON_CHANGE_TO_TRUE, ACTION_PLAY_SOUND, ACTION_RESET_DELAYED_SENSOR, ACTION_RESET_DELAYED_TURNOUT, ACTION_RUN_SCRIPT, ACTION_SET_BLOCK_ERROR, ACTION_SET_BLOCK_IN_SERVICE, ACTION_SET_BLOCK_OUT_OF_SERVICE, ACTION_SET_BLOCK_VALUE, ACTION_SET_FAST_CLOCK_TIME, ACTION_SET_LIGHT, ACTION_SET_LIGHT_INTENSITY, ACTION_SET_LIGHT_TRANSITION_TIME, ACTION_SET_MEMORY, ACTION_SET_NXPAIR_DISABLED, ACTION_SET_NXPAIR_ENABLED, ACTION_SET_NXPAIR_SEGMENT, ACTION_SET_ROUTE_TURNOUTS, ACTION_SET_SENSOR, ACTION_SET_SIGNAL_APPEARANCE, ACTION_SET_SIGNAL_DARK, ACTION_SET_SIGNAL_HELD, ACTION_SET_SIGNAL_LIT, ACTION_SET_SIGNALMAST_ASPECT, ACTION_SET_SIGNALMAST_DARK, ACTION_SET_SIGNALMAST_HELD, ACTION_SET_SIGNALMAST_LIT, ACTION_SET_TRAIN_ID, ACTION_SET_TRAIN_NAME, ACTION_SET_TURNOUT, ACTION_START_FAST_CLOCK, ACTION_STOP_FAST_CLOCK, ACTION_TRIGGER_ROUTE, ALL_AND, ALL_OR, FALSE, ITEM_TYPE_AUDIO, ITEM_TYPE_CLOCK, ITEM_TYPE_CONDITIONAL, ITEM_TYPE_ENTRYEXIT, ITEM_TYPE_LIGHT, ITEM_TYPE_LOGIX, ITEM_TYPE_MEMORY, ITEM_TYPE_OBLOCK, ITEM_TYPE_OTHER, ITEM_TYPE_SCRIPT, ITEM_TYPE_SENSOR, ITEM_TYPE_SIGNALHEAD, ITEM_TYPE_SIGNALMAST, ITEM_TYPE_TURNOUT, ITEM_TYPE_WARRANT, MIXED, NUM_ACTION_OPTIONS, OPERATOR_AND, OPERATOR_NONE, OPERATOR_OR, rbxWarrant, TRUE, TYPE_BLOCK_STATUS_EQUALS, TYPE_CONDITIONAL_FALSE, TYPE_CONDITIONAL_TRUE, TYPE_ENTRYEXIT_ACTIVE, TYPE_ENTRYEXIT_INACTIVE, TYPE_ERROR, TYPE_FAST_CLOCK_RANGE, TYPE_LIGHT_OFF, TYPE_LIGHT_ON, TYPE_MEMORY_COMPARE, TYPE_MEMORY_COMPARE_INSENSITIVE, TYPE_MEMORY_EQUALS, TYPE_MEMORY_EQUALS_INSENSITIVE, TYPE_NONE, TYPE_OBLOCK_ALLOCATED, TYPE_OBLOCK_DARK, TYPE_OBLOCK_OCCUPIED, TYPE_OBLOCK_OUT_OF_SERVICE, TYPE_OBLOCK_POWER_ERROR, TYPE_OBLOCK_RUNNING, TYPE_OBLOCK_UNOCCUPIED, TYPE_ROUTE_ALLOCATED, TYPE_ROUTE_FREE, TYPE_ROUTE_OCCUPIED, TYPE_ROUTE_SET, TYPE_SENSOR_ACTIVE, TYPE_SENSOR_INACTIVE, TYPE_SIGNAL_HEAD_APPEARANCE_EQUALS, TYPE_SIGNAL_HEAD_DARK, TYPE_SIGNAL_HEAD_FLASHGREEN, TYPE_SIGNAL_HEAD_FLASHLUNAR, TYPE_SIGNAL_HEAD_FLASHRED, TYPE_SIGNAL_HEAD_FLASHYELLOW, TYPE_SIGNAL_HEAD_GREEN, TYPE_SIGNAL_HEAD_HELD, TYPE_SIGNAL_HEAD_LIT, TYPE_SIGNAL_HEAD_LUNAR, TYPE_SIGNAL_HEAD_RED, TYPE_SIGNAL_HEAD_YELLOW, TYPE_SIGNAL_MAST_ASPECT_EQUALS, TYPE_SIGNAL_MAST_HELD, TYPE_SIGNAL_MAST_LIT, TYPE_TRAIN_RUNNING, TYPE_TURNOUT_CLOSED, TYPE_TURNOUT_THROWN, TYPE_XXXXXXX
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description DefaultConditional(java.lang.String systemName)
DefaultConditional(java.lang.String systemName, java.lang.String userName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description int
calculate(boolean enabled, java.beans.PropertyChangeEvent evt)
Calculate this Conditional.void
cancelSensorTimer(java.lang.String sname)
Stop a sensor timer if one is actively delaying setting of the specified sensorvoid
cancelTurnoutTimer(java.lang.String sname)
Stop a turnout timer if one is actively delaying setting of the specified turnoutvoid
dispose()
Dispose this DefaultConditional.java.util.List<ConditionalAction>
getActionList()
Get the list of actions for this conditional.java.lang.String
getAntecedentExpression()
Get antecedent (boolean string expression) of Conditional.java.lang.String
getBeanType()
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.java.util.List<ConditionalAction>
getCopyOfActions()
Make deep clone of actions.java.util.List<ConditionalVariable>
getCopyOfStateVariables()
Make deep clone of variables.static int
getIndexInTable(int[] table, int entry)
(package private) int
getIntegerValue(ConditionalAction action)
Get an integer from either a String literal or named memory reference.Conditional.AntecedentOperator
getLogicType()
Get type of operators in the antecedent statement.(package private) 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.int
getState()
State of the Conditional is returned.java.util.List<ConditionalVariable>
getStateVariableList()
Get the list of state variables for this Conditional.boolean
getTriggerOnChange()
(package private) DefaultConditional.DataPair
parseCalculate(java.lang.String s, java.util.List<ConditionalVariable> variableList)
Parses and computes one parenthesis level of a boolean statement.void
setAction(java.util.List<ConditionalAction> arrayList)
Set list of actions.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)void
setState(int state)
State of Conditional is set.void
setStateVariables(java.util.List<ConditionalVariable> arrayList)
Set State Variables for this Conditional.void
setTriggerOnChange(boolean trigger)
Set policy for execution of action listjava.lang.String
validateAntecedent(java.lang.String ant, java.util.List<ConditionalVariable> variableList)
Check that an antecedent is well formed.(package private) boolean
wantsToTrigger(java.beans.PropertyChangeEvent evt)
Check if an event will trigger actions.-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, describeState, equals, firePropertyChange, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, hashCode, removeProperty, removePropertyChangeListener, removePropertyChangeListener, setComment, setProperty, setUserName, toString, toStringSuffix, updateListenerRef, vetoableChange
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.Conditional
addPropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getRecommendedToolTip, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
-
-
-
-
Field Detail
-
rbx
static final java.util.ResourceBundle rbx
-
_actionList
protected java.util.List<ConditionalAction> _actionList
-
-
Constructor Detail
-
DefaultConditional
public DefaultConditional(java.lang.String systemName, java.lang.String userName)
-
DefaultConditional
public DefaultConditional(java.lang.String systemName)
-
-
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 interfaceNamedBean
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
getIndexInTable
public static int getIndexInTable(int[] table, int entry)
-
getAntecedentExpression
public java.lang.String getAntecedentExpression()
Get antecedent (boolean string expression) of Conditional.- Specified by:
getAntecedentExpression
in interfaceConditional
- Returns:
- the expression
-
getLogicType
public Conditional.AntecedentOperator getLogicType()
Get type of operators in the antecedent statement.- Specified by:
getLogicType
in interfaceConditional
- Returns:
- the type
-
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 interfaceConditional
- Parameters:
type
- index of the logic typeantecedent
- non-localized (US-english) string description of antecedent
-
getTriggerOnChange
public boolean getTriggerOnChange()
- Specified by:
getTriggerOnChange
in interfaceConditional
- 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 interfaceConditional
- Parameters:
trigger
- true execute only on change 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 interfaceConditional
- Parameters:
arrayList
- the list of variables
-
getCopyOfStateVariables
@Nonnull public java.util.List<ConditionalVariable> getCopyOfStateVariables()
Make deep clone of variables.- Specified by:
getCopyOfStateVariables
in interfaceConditional
- Returns:
- a list containing copies of variables
-
getStateVariableList
public java.util.List<ConditionalVariable> getStateVariableList()
Get the list of state variables for this Conditional.- Returns:
- the list of state variables
-
setAction
public void setAction(java.util.List<ConditionalAction> arrayList)
Set list of actions.- Specified by:
setAction
in interfaceConditional
- Parameters:
arrayList
- the actions
-
getCopyOfActions
@Nonnull public java.util.List<ConditionalAction> getCopyOfActions()
Make deep clone of actions.- Specified by:
getCopyOfActions
in interfaceConditional
- Returns:
- a list of copies of actions
-
getActionList
public java.util.List<ConditionalAction> getActionList()
Get the list of actions for this conditional.- Returns:
- the list of actions
-
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 interfaceConditional
- Parameters:
enabled
- true if Logix should be enabled; false otherwiseevt
- 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 interfaceConditional
- Parameters:
ant
- the antecedent string descriptionvariableList
- 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 parsedvariableList
- 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 interfaceConditional
- 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 interfaceConditional
- Parameters:
sname
- the name of the timer
-
getState
public int getState()
State of the Conditional is returned.- Specified by:
getState
in interfaceConditional
- Specified by:
getState
in interfaceNamedBean
- 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.
-
dispose
public void dispose()
Dispose this DefaultConditional.- Specified by:
dispose
in interfaceConditional
- Specified by:
dispose
in interfaceNamedBean
- Overrides:
dispose
in classAbstractNamedBean
-
-