Package jmri.implementation
Class DefaultConditional
java.lang.Object
jmri.implementation.AbstractNamedBean
jmri.implementation.DefaultConditional
- All Implemented Interfaces:
Comparable<NamedBean>,PropertyChangeProvider,Conditional,NamedBean
- Direct Known Subclasses:
SensorGroupConditional
Class providing the basic logic of the Conditional interface.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classClass for defining ActionListener for ACTION_DELAYED_SENSOR(package private) classClass for defining ActionListener for ACTION_DELAYED_TURNOUTNested classes/interfaces inherited from interface jmri.Conditional
Conditional.Action, Conditional.AntecedentOperator, Conditional.ItemType, Conditional.Operator, Conditional.State, Conditional.TypeNested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected List<ConditionalAction>(package private) static final ResourceBundleFields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, registerFields 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_XXXXXXXFields 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
ConstructorsConstructorDescriptionDefaultConditional(String systemName) DefaultConditional(String systemName, String userName) -
Method Summary
Modifier and TypeMethodDescriptionintcalculate(boolean enable, PropertyChangeEvent evt) Calculate this Conditional.voidcancelSensorTimer(String sname) Stop a sensor timer if one is actively delaying setting of the specified sensorvoidcancelTurnoutTimer(String sname) Stop a turnout timer if one is actively delaying setting of the specified turnoutvoiddispose()Dispose this DefaultConditional.Get the list of actions for this conditional.Get antecedent (boolean string expression) of Conditional.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.Make deep clone of actions.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.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.Get the list of state variables for this Conditional.boolean(package private) jmri.implementation.DefaultConditional.DataPairparseCalculate(String expression, List<ConditionalVariable> variableList) Parses and computes one parenthesis level of a boolean statement.voidsetAction(List<ConditionalAction> arrayList) Set list of actions.voidsetLogicType(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)voidsetState(int state) State of Conditional is set.voidsetStateVariables(List<ConditionalVariable> arrayList) Set State Variables for this Conditional.voidsetTriggerOnChange(boolean trigger) Set policy for execution of action listvalidateAntecedent(String ant, List<ConditionalVariable> variableList) Check that an antecedent is well formed.(package private) booleanCheck 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, vetoableChangeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.Conditional
addPropertyChangeListener, removePropertyChangeListenerMethods 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, vetoableChangeMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
-
Field Details
-
conditionalRbx
-
_actionList
-
-
Constructor Details
-
DefaultConditional
-
DefaultConditional
-
-
Method Details
-
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
-
getAntecedentExpression
Get antecedent (boolean string expression) of Conditional.- Specified by:
getAntecedentExpressionin interfaceConditional- Returns:
- the expression
-
getLogicType
Get type of operators in the antecedent statement.- Specified by:
getLogicTypein interfaceConditional- Returns:
- the type
-
setLogicType
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
- 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
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
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
Make deep clone of variables.- Specified by:
getCopyOfStateVariablesin interfaceConditional- Returns:
- a list containing copies of variables
-
getStateVariableList
Get the list of state variables for this Conditional.- Returns:
- the list of state variables
-
setAction
Set list of actions.- Specified by:
setActionin interfaceConditional- Parameters:
arrayList- the actions
-
getCopyOfActions
Make deep clone of actions.- Specified by:
getCopyOfActionsin interfaceConditional- Returns:
- a list of copies of actions
-
getActionList
Get the list of actions for this conditional.- Returns:
- the list of actions
-
calculate
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
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 String validateAntecedent(@Nonnull String ant, 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(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 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
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
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
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
State of the Conditional is returned.- Specified by:
getStatein interfaceConditional- Specified by:
getStatein interfaceNamedBean- Returns:
- state value
-
setState
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
Dispose this DefaultConditional.- Specified by:
disposein interfaceConditional- Specified by:
disposein interfaceNamedBean- Overrides:
disposein classAbstractNamedBean
-