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) classDefaultConditional.TimeSensorClass for defining ActionListener for ACTION_DELAYED_SENSOR(package private) classDefaultConditional.TimeTurnoutClass 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.ResourceBundleconditionalRbx-
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, rbx, 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_COMMENT, PROPERTY_ENABLED, PROPERTY_KNOWN_STATE, PROPERTY_STATE, PROPERTY_USERNAME, 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 intcalculate(boolean enable, java.beans.PropertyChangeEvent evt)Calculate this Conditional.voidcancelSensorTimer(java.lang.String sname)Stop a sensor timer if one is actively delaying setting of the specified sensorvoidcancelTurnoutTimer(java.lang.String sname)Stop a turnout timer if one is actively delaying setting of the specified turnoutvoiddispose()Dispose this DefaultConditional.java.util.List<ConditionalAction>getActionList()Get the list of actions for this conditional.java.lang.StringgetAntecedentExpression()Get antecedent (boolean string expression) of Conditional.java.lang.StringgetBeanType()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 intgetIndexInTable(int[] table, int entry)(package private) intgetIntegerValue(ConditionalAction action)Get an integer from either a String literal or named memory reference.Conditional.AntecedentOperatorgetLogicType()Get type of operators in the antecedent statement.(package private) intgetMillisecondValue(ConditionalAction action)Get the number of milliseconds from either a String literal or named memory reference containing a value representing a number of seconds.intgetState()State of the Conditional is returned.java.util.List<ConditionalVariable>getStateVariableList()Get the list of state variables for this Conditional.booleangetTriggerOnChange()(package private) jmri.implementation.DefaultConditional.DataPairparseCalculate(java.lang.String expression, java.util.List<ConditionalVariable> variableList)Parses and computes one parenthesis level of a boolean statement.voidsetAction(java.util.List<ConditionalAction> arrayList)Set list of actions.voidsetLogicType(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)voidsetState(int state)State of Conditional is set.voidsetStateVariables(java.util.List<ConditionalVariable> arrayList)Set State Variables for this Conditional.voidsetTriggerOnChange(boolean trigger)Set policy for execution of action listjava.lang.StringvalidateAntecedent(java.lang.String ant, java.util.List<ConditionalVariable> variableList)Check that an antecedent is well formed.(package private) booleanwantsToTrigger(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
-
conditionalRbx
static final java.util.ResourceBundle conditionalRbx
-
_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:NamedBeanFor 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:
getBeanTypein 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:
getAntecedentExpressionin interfaceConditional- Returns:
- the expression
-
getLogicType
public Conditional.AntecedentOperator getLogicType()
Get type of operators in the antecedent statement.- Specified by:
getLogicTypein 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:
setLogicTypein interfaceConditional- Parameters:
type- index of the logic typeantecedent- non-localized (US-english) string description of antecedent
-
getTriggerOnChange
public boolean getTriggerOnChange()
- Specified by:
getTriggerOnChangein 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:ConditionalSet policy for execution of action list- Specified by:
setTriggerOnChangein interfaceConditional- Parameters:
trigger- true execute only on change of state
-
setStateVariables
public void setStateVariables(@Nonnull 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:
setStateVariablesin interfaceConditional- Parameters:
arrayList- the list of variables
-
getCopyOfStateVariables
@Nonnull public java.util.List<ConditionalVariable> getCopyOfStateVariables()
Make deep clone of variables.- Specified by:
getCopyOfStateVariablesin 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(@Nonnull java.util.List<ConditionalAction> arrayList)
Set list of actions.- Specified by:
setActionin interfaceConditional- Parameters:
arrayList- the actions
-
getCopyOfActions
@Nonnull public java.util.List<ConditionalAction> getCopyOfActions()
Make deep clone of actions.- Specified by:
getCopyOfActionsin interfaceConditional- Returns:
- a list of copies of actions
-
getActionList
@Nonnull public java.util.List<ConditionalAction> getActionList()
Get the list of actions for this conditional.- Returns:
- the list of actions
-
calculate
public int calculate(boolean enable, 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:
calculatein interfaceConditional- Parameters:
enable- true to enable, else false.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
@CheckForNull public java.lang.String validateAntecedent(@Nonnull java.lang.String ant, java.util.List<ConditionalVariable> variableList)
Check that an antecedent is well formed.- Specified by:
validateAntecedentin interfaceConditional- Parameters:
ant- the antecedent string descriptionvariableList- arraylist of existing Conditional variables- Returns:
- error message string if not well formed
-
parseCalculate
jmri.implementation.DefaultConditional.DataPair parseCalculate(java.lang.String expression, 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:
expression- 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(@Nonnull 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(@Nonnull ConditionalAction action)
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(java.lang.String sname)
Stop a sensor timer if one is actively delaying setting of the specified sensor- Specified by:
cancelSensorTimerin 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:
cancelTurnoutTimerin interfaceConditional- Parameters:
sname- the name of the timer
-
getState
public int getState()
State of the Conditional is returned.- Specified by:
getStatein interfaceConditional- Specified by:
getStatein 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:
disposein interfaceConditional- Specified by:
disposein interfaceNamedBean- Overrides:
disposein classAbstractNamedBean
-
-