Class DefaultLogix
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.DefaultLogix
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>
,PropertyChangeProvider
,Logix
,NamedBean
public class DefaultLogix extends AbstractNamedBean implements Logix
Class providing the basic logic of the Logix interface.
-
-
Nested Class Summary
-
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 (package private) java.util.HashMap<java.lang.String,Conditional>
_conditionalMap
Maintain a list of conditional objects.(package private) java.util.ArrayList<java.lang.String>
_conditionalSystemNames
Persistant instance variables (saved between runs).(package private) java.util.ArrayList<JmriSimplePropertyListener>
_listeners
(package private) static java.util.regex.Pattern
NXUUID
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.Logix
LISTENER_TYPE_CONDITIONAL, LISTENER_TYPE_ENTRYEXIT, LISTENER_TYPE_FASTCLOCK, LISTENER_TYPE_LIGHT, LISTENER_TYPE_MEMORY, LISTENER_TYPE_OBLOCK, LISTENER_TYPE_SENSOR, LISTENER_TYPE_SIGNALHEAD, LISTENER_TYPE_SIGNALMAST, LISTENER_TYPE_TURNOUT, LISTENER_TYPE_WARRANT
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description DefaultLogix(java.lang.String systemName)
DefaultLogix(java.lang.String systemName, java.lang.String userName)
DefaultLogix(java.lang.String systemName, java.lang.String userName, ConditionalManager conditionalManager)
DefaultLogix(java.lang.String systemName, ConditionalManager conditionalManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
activateLogix()
Activate the Logix, starts Logix processing by connecting all inputs that are included the Conditionals in this Logix.void
addConditional(java.lang.String systemName, int order)
Add a Conditional to this Logix Rboolean
addConditional(java.lang.String systemName, Conditional conditional)
Add a child Conditional to the parent Logix.void
calculateConditionals()
Calculate all Conditionals, triggering action if the user specified conditions are met, and the Logix is enabled.void
deActivateLogix()
Deactivate the Logix.java.lang.String[]
deleteConditional(java.lang.String systemName)
Delete a Conditional and remove it from this Logixvoid
dispose()
Deactivate this object, so that it releases as many resources as possible and no longer effects others.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.Conditional
getConditional(java.lang.String systemName)
Get a Conditional belonging to this Logix.java.lang.String
getConditionalByNumberOrder(int order)
Returns the system name of the conditional that will calculate in the specified order.boolean
getEnabled()
Get enabled statusint
getNumConditionals()
Get number of Conditionals for this Logixint
getState()
Not needed for Logixs - included to complete implementation of the NamedBean interface.java.util.List<NamedBeanUsageReport>
getUsageReport(NamedBean bean)
Get a list of references for the specified bean.void
setEnabled(boolean state)
Set enabled status.void
setGuiNames()
ConditionalVariables only have a single name field.void
setState(int state)
Not needed for Logixs - included to complete implementation of the NamedBean interface.void
swapConditional(int nextInOrder, int row)
Move 'row' to 'nextInOrder' and shift all between 'row' and 'nextInOrder' up one position ( row > nextInOrder )void
vetoableChange(java.beans.PropertyChangeEvent evt)
-
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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareSystemNameSuffix, compareTo, describeState, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getSystemName, getUserName, removeProperty, setComment, setProperty, setUserName, toString, updateListenerRef
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Field Detail
-
_conditionalSystemNames
java.util.ArrayList<java.lang.String> _conditionalSystemNames
Persistant instance variables (saved between runs). Order is significant.
-
_listeners
java.util.ArrayList<JmriSimplePropertyListener> _listeners
-
_conditionalMap
java.util.HashMap<java.lang.String,Conditional> _conditionalMap
Maintain a list of conditional objects. The key is the conditional system name- Since:
- 4.7.4
-
NXUUID
static final java.util.regex.Pattern NXUUID
-
-
Constructor Detail
-
DefaultLogix
public DefaultLogix(java.lang.String systemName, java.lang.String userName)
-
DefaultLogix
public DefaultLogix(java.lang.String systemName, java.lang.String userName, ConditionalManager conditionalManager)
-
DefaultLogix
public DefaultLogix(java.lang.String systemName)
-
DefaultLogix
public DefaultLogix(java.lang.String systemName, ConditionalManager conditionalManager)
-
-
Method Detail
-
getBeanType
@Nonnull 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
-
getNumConditionals
public int getNumConditionals()
Get number of Conditionals for this Logix- Specified by:
getNumConditionals
in interfaceLogix
- Returns:
- the number of conditionals
-
swapConditional
public void swapConditional(int nextInOrder, int row)
Move 'row' to 'nextInOrder' and shift all between 'row' and 'nextInOrder' up one position ( row > nextInOrder )- Specified by:
swapConditional
in interfaceLogix
- Parameters:
nextInOrder
- target order for Conditional at rowrow
- position of Conditional to move
-
getConditionalByNumberOrder
public java.lang.String getConditionalByNumberOrder(int order)
Returns the system name of the conditional that will calculate in the specified order. This is also the order the Conditional is listed in the Add/Edit Logix dialog. If 'order' is greater than the number of Conditionals for this Logix, and empty String is returned.- Specified by:
getConditionalByNumberOrder
in interfaceLogix
- Parameters:
order
- order in which the Conditional calculates.- Returns:
- system name of conditional or an empty String
-
addConditional
public void addConditional(java.lang.String systemName, int order)
Add a Conditional to this Logix R- Specified by:
addConditional
in interfaceLogix
- Parameters:
systemName
- The Conditional system nameorder
- the order this conditional should calculate in if order is negative, the conditional is added at the end of current group of conditionals
-
addConditional
public boolean addConditional(java.lang.String systemName, Conditional conditional)
Add a child Conditional to the parent Logix.- Specified by:
addConditional
in interfaceLogix
- Parameters:
systemName
- The system name for the Conditional object.conditional
- The Conditional object.- Returns:
- true if the Conditional was added, false otherwise.
- Since:
- 4.7.4
-
getConditional
public Conditional getConditional(java.lang.String systemName)
Get a Conditional belonging to this Logix.- Specified by:
getConditional
in interfaceLogix
- Parameters:
systemName
- The name of the Conditional object.- Returns:
- the Conditional object or null if not found.
- Since:
- 4.7.4
-
setEnabled
public void setEnabled(boolean state)
Set enabled status. Enabled is a bound property All conditionals are set to UNKNOWN state and recalculated when the Logix is enabled, provided the Logix has been previously activated.- Specified by:
setEnabled
in interfaceLogix
- Parameters:
state
- true if Logix should be enabled; false otherwise
-
getEnabled
public boolean getEnabled()
Get enabled status- Specified by:
getEnabled
in interfaceLogix
- Returns:
- true if enabled; false otherwise
-
deleteConditional
public java.lang.String[] deleteConditional(java.lang.String systemName)
Delete a Conditional and remove it from this LogixNote: Since each Logix must have at least one Conditional to do anything, the user is warned in Logix Table Action when the last Conditional is deleted.
- Specified by:
deleteConditional
in interfaceLogix
- Parameters:
systemName
- The Conditional system name- Returns:
- null if Conditional was successfully deleted or not present, otherwise returns a string array list of current usage that prevent deletion, used to present a warning dialog to the user
-
calculateConditionals
public void calculateConditionals()
Calculate all Conditionals, triggering action if the user specified conditions are met, and the Logix is enabled.- Specified by:
calculateConditionals
in interfaceLogix
-
activateLogix
public void activateLogix()
Activate the Logix, starts Logix processing by connecting all inputs that are included the Conditionals in this Logix.A Logix must be activated before it will calculate any of its Conditionals.
- Specified by:
activateLogix
in interfaceLogix
-
setGuiNames
public void setGuiNames()
ConditionalVariables only have a single name field. For user interface purposes a gui name is used for the referenced conditional user name. This is not used for other object types.In addition to setting the GUI name, any state variable references are changed to conditional system names. This converts the XML system/user name field to the system name for conditional references. It does not affect other objects such as sensors, turnouts, etc.
For Entry/Exit references, replace NX user names and old style NX UUID references with the new style "IN:" + UUID reference. If the referenced NX does not exist, it will be removed from the Variable or Action list. (4.11.4)
Called by
DefaultLogixManager.activateAllLogixs()
- Specified by:
setGuiNames
in interfaceLogix
- Since:
- 4.7.4
-
deActivateLogix
public void deActivateLogix()
Deactivate the Logix. This method disconnects the Logix from all input objects and stops it from being triggered to calculate.A Logix must be deactivated before its Conditionals are changed.
- Specified by:
deActivateLogix
in interfaceLogix
-
getState
public int getState()
Not needed for Logixs - included to complete implementation of the NamedBean interface.
-
setState
public void setState(int state)
Not needed for Logixs - included to complete implementation of the NamedBean interface.
-
vetoableChange
public void vetoableChange(java.beans.PropertyChangeEvent evt) throws java.beans.PropertyVetoException
Description copied from class:AbstractNamedBean
- Specified by:
vetoableChange
in interfaceNamedBean
- Overrides:
vetoableChange
in classAbstractNamedBean
- Throws:
java.beans.PropertyVetoException
-
getUsageReport
public java.util.List<NamedBeanUsageReport> getUsageReport(NamedBean bean)
Description copied from interface:NamedBean
Get a list of references for the specified bean.- Specified by:
getUsageReport
in interfaceNamedBean
- Parameters:
bean
- The bean to be checked.- Returns:
- a list of NamedBeanUsageReports or an empty ArrayList.
-
dispose
@OverridingMethodsMustInvokeSuper public void dispose()
Deactivate this object, so that it releases as many resources as possible and no longer effects others.For example, if this object has listeners, after a call to this method it should no longer notify those listeners. Any native or system-wide resources it maintains should be released, including threads, files, etc.
It is an error to invoke any other methods on this object once dispose() has been called. Note, however, that there is no guarantee about behavior in that case.
Afterwards, references to this object may still exist elsewhere, preventing its garbage collection. But it's formally dead, and shouldn't be keeping any other objects alive. Therefore, this method should null out any references to other objects that this NamedBean contained.
- Specified by:
dispose
in interfaceNamedBean
- Overrides:
dispose
in classAbstractNamedBean
-
-