Package jmri.implementation
Class AbstractAnalogIO
- java.lang.Object
-
- jmri.implementation.AbstractNamedBean
-
- jmri.implementation.AbstractAnalogIO
-
- All Implemented Interfaces:
java.lang.Comparable<NamedBean>
,AnalogIO
,PropertyChangeProvider
,NamedBean
- Direct Known Subclasses:
DefaultMeter
public abstract class AbstractAnalogIO extends AbstractNamedBean implements AnalogIO
Base implementation of the AnalogIO interface.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.AnalogIO
AnalogIO.AbsoluteOrRelative
-
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException
-
-
Field Summary
-
Fields inherited from class jmri.implementation.AbstractNamedBean
listenerRefs, mSystemName, register
-
Fields inherited from interface jmri.NamedBean
DISPLAY_NAME_FORMAT, INCONSISTENT, PROPERTY_STATE, QUOTED_NAME_FORMAT, UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description AbstractAnalogIO(java.lang.String systemName, boolean commandedValueSetsKnownValue)
Abstract constructor for new AnalogIO with system nameAbstractAnalogIO(java.lang.String systemName, java.lang.String userName, boolean commandedValueSetsKnownValue)
Abstract constructor for new AnalogIO with system name and user name
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description int
compareSystemNameSuffix(java.lang.String suffix1, java.lang.String suffix2, NamedBean n)
Compare the suffix of this NamedBean's name with the suffix of the argument NamedBean's name for theNamedBean.compareTo(jmri.NamedBean)
operation.protected abstract boolean
cutOutOfBoundsValues()
Cut out of bounds values instead of throwing an exception?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.double
getCommandedAnalogValue()
Query the commanded value.double
getKnownAnalogValue()
Query the known analog value.double
getState(double v)
Provide generic access to internal state.protected abstract void
sendValueToLayout(double value)
Sends the string to the layout.void
setCommandedAnalogValue(double value)
Change the commanded value, which results in the relevant command(s) being sent to the hardware.void
setState(double value)
Provide generic access to internal state.protected void
setValue(double newValue)
Set the value of this AnalogIO.-
Methods inherited from class jmri.implementation.AbstractNamedBean
addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, addPropertyChangeListener, describeState, dispose, 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.AnalogIO
getAbsoluteOrRelative, getMax, getMin, getResolution, isConsistentValue, requestUpdateFromLayout
-
Methods inherited from interface jmri.NamedBean
addPropertyChangeListener, addPropertyChangeListener, compareTo, describeState, dispose, getComment, getDisplayName, getDisplayName, getListenerRef, getListenerRefs, getNumPropertyChangeListeners, getProperty, getPropertyChangeListenersByReference, getPropertyKeys, getState, getSystemName, getUsageReport, getUserName, removeProperty, setComment, setProperty, setState, setUserName, toString, updateListenerRef, vetoableChange
-
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
-
-
-
Constructor Detail
-
AbstractAnalogIO
public AbstractAnalogIO(@Nonnull java.lang.String systemName, boolean commandedValueSetsKnownValue)
Abstract constructor for new AnalogIO with system name- Parameters:
systemName
- AnalogIO system namecommandedValueSetsKnownValue
- true if setCommandedValue() also sets known value, false othervise
-
AbstractAnalogIO
public AbstractAnalogIO(@Nonnull java.lang.String systemName, @CheckForNull java.lang.String userName, boolean commandedValueSetsKnownValue)
Abstract constructor for new AnalogIO with system name and user name- Parameters:
systemName
- AnalogIO system nameuserName
- AnalogIO user namecommandedValueSetsKnownValue
- true if setCommandedValue() also sets known value, false othervise
-
-
Method Detail
-
sendValueToLayout
protected abstract void sendValueToLayout(double value) throws JmriException
Sends the string to the layout. The string [u]must not[/u] be longer than the value of getMaximumLength() unless that value is zero. Some microcomputers have little memory and it's very important that this method is never called with too long strings.- Parameters:
value
- the desired string value- Throws:
JmriException
- general error when setting the value fails
-
setValue
protected void setValue(double newValue)
Set the value of this AnalogIO. Called from the implementation class when the layout updates this AnalogIO.- Parameters:
newValue
- the new value
-
setCommandedAnalogValue
public void setCommandedAnalogValue(double value) throws JmriException
Change the commanded value, which results in the relevant command(s) being sent to the hardware. The exception is thrown if there are problems communicating with the layout hardware.The value must be a valid number, not a NaN or infinity number.
- Specified by:
setCommandedAnalogValue
in interfaceAnalogIO
- Parameters:
value
- the desired analog value- Throws:
JmriException
- general error when setting the value fails
-
getCommandedAnalogValue
public double getCommandedAnalogValue()
Query the commanded value. This is a bound parameter, so you can also register a listener to be informed of changes.The result must be a valid number, not a NaN or infinity number.
- Specified by:
getCommandedAnalogValue
in interfaceAnalogIO
- Returns:
- the analog value
-
getKnownAnalogValue
public double getKnownAnalogValue()
Query the known analog value. This is a bound parameter, so you can also register a listener to be informed of changes. A result is always returned; if no other feedback method is available, the commanded value will be used.The result must be a valid number, not a NaN or infinity number.
- Specified by:
getKnownAnalogValue
in interfaceAnalogIO
- Returns:
- the known analog value
-
cutOutOfBoundsValues
protected abstract boolean cutOutOfBoundsValues()
Cut out of bounds values instead of throwing an exception? For example, if the AnalogIO is a display, it could be desired to accept too long strings. On the other hand, if the AnalogIO is used to send a command, a too long string is an error.- Returns:
- true if long strings should be cut
-
getState
public double getState(double v)
Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (getCommandedAnalogValue). This is provided to make scripts easier to read.
-
setState
public void setState(double value) throws JmriException
Provide generic access to internal state.This generally shouldn't be used by Java code; use the class-specific form instead (setCommandedAnalogValue). This is provided to make scripts access easier to read.
- Specified by:
setState
in interfaceAnalogIO
- Parameters:
value
- the analog value- Throws:
JmriException
- general error when setting the state fails
-
getBeanType
@Nonnull public 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.- Specified by:
getBeanType
in interfaceNamedBean
- Returns:
- a string of the bean type, eg Turnout, Sensor etc
-
compareSystemNameSuffix
@CheckReturnValue public int compareSystemNameSuffix(@Nonnull java.lang.String suffix1, @Nonnull java.lang.String suffix2, @Nonnull NamedBean n)
Compare the suffix of this NamedBean's name with the suffix of the argument NamedBean's name for theNamedBean.compareTo(jmri.NamedBean)
operation. This is intended to be a system-specific comparison that understands the various formats, etc. By default, does an alphanumeric-by-chunks comparison. Do a string comparison.- Specified by:
compareSystemNameSuffix
in interfaceNamedBean
- Overrides:
compareSystemNameSuffix
in classAbstractNamedBean
- Parameters:
suffix1
- The suffix for the 1st bean in the comparisonsuffix2
- The suffix for the 2nd bean in the comparisonn
- The other (second) NamedBean in the comparison- Returns:
- -1,0,+1 for ordering if the names are well-formed; may not provide proper ordering if the names are not well-formed.
-
-