Class AbstractNamedBean
- All Implemented Interfaces:
Comparable<NamedBean>,PropertyChangeProvider,NamedBean
- Direct Known Subclasses:
AbstractAnalogIO,AbstractAudio,AbstractBase,AbstractIdTag,AbstractLight,AbstractMemory,AbstractNamedTable,AbstractReporter,AbstractSensor,AbstractSignalHead,AbstractSignalMast,AbstractStringIO,AbstractTurnout,Block,DefaultConditional,DefaultGlobalVariable,DefaultLogix,DefaultLogixNG,DefaultRoute,DefaultSection,DefaultSignalAppearanceMap,DefaultSignalGroup,DefaultSignalMastLogic,DefaultSignalSystem,DefaultTransit,DestinationPoints,LayoutBlock,SimpleTimebase,Warrant
Implements the parameter binding support.
-
Nested Class Summary
Nested classes/interfaces inherited from interface jmri.NamedBean
NamedBean.BadNameException, NamedBean.BadSystemNameException, NamedBean.BadUserNameException, NamedBean.DisplayOptions, NamedBean.DuplicateSystemNameException -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final HashMap<PropertyChangeListener,String> protected final Stringprotected final HashMap<PropertyChangeListener,String> 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
ConstructorsModifierConstructorDescriptionprotectedAbstractNamedBean(String sys) Create a new NamedBean instance using only a system name.protectedAbstractNamedBean(String sys, String user) Create a new NamedBean instance using both a system name and (optionally) a user name. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd aPropertyChangeListenerto the listener list.voidaddPropertyChangeListener(PropertyChangeListener l, String beanRef, String listenerRef) Request a call-back when a bound property changes.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener) Add aPropertyChangeListenerfor a specific property.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener l, String beanRef, String listenerRef) Request a call-back when a bound property changes.intcompareSystemNameSuffix(String suffix1, 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.describeState(int state) Provide human-readable, localized version of state value.voiddispose()Deactivate this object, so that it releases as many resources as possible and no longer effects others.booleanprotected voidfirePropertyChange(String p, Object old, Object n) final StringGet associated comment text.final StringGet user name if it exists, otherwise return System name.final StringgetDisplayName(NamedBean.DisplayOptions displayOptions) Get the name to display, formatted perNamedBean.DisplayOptions.Get the textual reference for the specific listenerGet a meaningful list of places where the bean is in use.intGet the number of current listeners.getProperty(String key) Retrieve the value associated with a key.Get allPropertyChangeListeners currently attached to this object.getPropertyChangeListeners(String propertyName) Get allPropertyChangeListeners currently listening to changes to the specified property.Get a list of all the property change listeners that are registered using a specific nameRetrieve the complete current set of keys.final StringGet a system-specific name.final StringUser's identification for the item.inthashCode()voidremoveProperty(String key) Remove the key/value pair against the NamedBean.voidRemove the specified listener from this object.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener) Remove the specified listener of the specified property from this object.final voidsetComment(String comment) Set associated comment text.voidsetProperty(String key, Object value) Attach a key/value pair to the NamedBean, which can be retrieved later.voidSet the user name, normalizing it if needed.final StringtoString()Display the system-specific name.protected StringOverload this in a sub-class to add extra info to the results of toString()voidupdateListenerRef(PropertyChangeListener l, String newName) voidMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface jmri.NamedBean
compareTo, getBeanType, getRecommendedToolTip, getState, getUsageReport, setState
-
Field Details
-
mSystemName
-
register
-
listenerRefs
-
-
Constructor Details
-
AbstractNamedBean
Create a new NamedBean instance using only a system name.- Parameters:
sys- the system name for this bean; must not be null and must be unique within the layout
-
AbstractNamedBean
protected AbstractNamedBean(@Nonnull String sys, @CheckForNull String user) throws NamedBean.BadUserNameException, NamedBean.BadSystemNameException Create a new NamedBean instance using both a system name and (optionally) a user name.Refuses construction if unable to use the normalized user name, to prevent subclass from overriding
setUserName(java.lang.String)during construction.- Parameters:
sys- the system name for this bean; must not be nulluser- the user name for this bean; will be normalized if needed; can be null- Throws:
NamedBean.BadUserNameException- if the user name cannot be normalizedNamedBean.BadSystemNameException- if the system name is null
-
-
Method Details
-
getComment
Get associated comment text.- Specified by:
getCommentin interfaceNamedBean- Returns:
- the comment or null
-
setComment
Set associated comment text.Comments can be any valid text.
- Specified by:
setCommentin interfaceNamedBean- Parameters:
comment- the comment or null to remove an existing comment
-
getDisplayName
Get user name if it exists, otherwise return System name.- Specified by:
getDisplayNamein interfaceNamedBean- Returns:
- the user name or system-specific name
-
getDisplayName
@CheckReturnValue @Nonnull public final String getDisplayName(NamedBean.DisplayOptions displayOptions) Get the name to display, formatted perNamedBean.DisplayOptions.- Specified by:
getDisplayNamein interfaceNamedBean- Parameters:
displayOptions- the DisplayOptions to use- Returns:
- the display name formatted per options
-
addPropertyChangeListener
@OverridingMethodsMustInvokeSuper public void addPropertyChangeListener(@Nonnull PropertyChangeListener l, String beanRef, String listenerRef) Request a call-back when a bound property changes. Bound properties are the known state, commanded state, user and system names.- Specified by:
addPropertyChangeListenerin interfaceNamedBean- Parameters:
l- The listener. This may change in the future to be a subclass of NamedProprtyChangeListener that carries the name and listenerRef values internallybeanRef- The name (either system or user) that the listener uses for this namedBean, this parameter is used to help determine when which listeners should be moved when the username is moved from one bean to anotherlistenerRef- A textual reference for the listener, that can be presented to the user when a delete is called
-
addPropertyChangeListener
@OverridingMethodsMustInvokeSuper public void addPropertyChangeListener(@Nonnull String propertyName, @Nonnull PropertyChangeListener l, String beanRef, String listenerRef) Request a call-back when a bound property changes. Bound properties are the known state, commanded state, user and system names.- Specified by:
addPropertyChangeListenerin interfaceNamedBean- Parameters:
propertyName- The name of the property to listen tol- The listener. This may change in the future to be a subclass of NamedProprtyChangeListener that carries the name and listenerRef values internallybeanRef- The name (either system or user) that the listener uses for this namedBean, this parameter is used to help determine when which listeners should be moved when the username is moved from one bean to anotherlistenerRef- A textual reference for the listener, that can be presented to the user when a delete is called
-
addPropertyChangeListener
@OverridingMethodsMustInvokeSuper public void addPropertyChangeListener(PropertyChangeListener listener) Add aPropertyChangeListenerto the listener list.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Parameters:
listener- The PropertyChangeListener to be added
-
addPropertyChangeListener
@OverridingMethodsMustInvokeSuper public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) Add aPropertyChangeListenerfor a specific property.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Parameters:
propertyName- The name of the property to listen on.listener- The PropertyChangeListener to be added
-
removePropertyChangeListener
@OverridingMethodsMustInvokeSuper public void removePropertyChangeListener(PropertyChangeListener listener) Remove the specified listener from this object.- Specified by:
removePropertyChangeListenerin interfacePropertyChangeProvider- Parameters:
listener- ThePropertyChangeListenerto remove.
-
removePropertyChangeListener
@OverridingMethodsMustInvokeSuper public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) Remove the specified listener of the specified property from this object.- Specified by:
removePropertyChangeListenerin interfacePropertyChangeProvider- Parameters:
propertyName- The name of the property to stop listening to.listener- ThePropertyChangeListenerto remove.
-
getPropertyChangeListenersByReference
@Nonnull public PropertyChangeListener[] getPropertyChangeListenersByReference(@Nonnull String name) Get a list of all the property change listeners that are registered using a specific name- Specified by:
getPropertyChangeListenersByReferencein interfaceNamedBean- Parameters:
name- The name (either system or user) that the listener has registered as referencing this namedBean- Returns:
- empty list if none
-
getListenerRefs
Get a meaningful list of places where the bean is in use.- Specified by:
getListenerRefsin interfaceNamedBean- Returns:
- ArrayList of the listeners
-
updateListenerRef
@OverridingMethodsMustInvokeSuper public void updateListenerRef(PropertyChangeListener l, String newName) - Specified by:
updateListenerRefin interfaceNamedBean
-
getListenerRef
Description copied from interface:NamedBeanGet the textual reference for the specific listener- Specified by:
getListenerRefin interfaceNamedBean- Parameters:
l- the listener of interest- Returns:
- the textual reference
-
getNumPropertyChangeListeners
Get the number of current listeners.- Specified by:
getNumPropertyChangeListenersin interfaceNamedBean- Returns:
- -1 if the information is not available for some reason.
-
getPropertyChangeListeners
Get allPropertyChangeListeners currently attached to this object.- Specified by:
getPropertyChangeListenersin interfacePropertyChangeProvider- Returns:
- An array of PropertyChangeListeners.
-
getPropertyChangeListeners
Get allPropertyChangeListeners currently listening to changes to the specified property.- Specified by:
getPropertyChangeListenersin interfacePropertyChangeProvider- Parameters:
propertyName- the name of the property of interest- Returns:
- an array of PropertyChangeListeners
-
getSystemName
Get a system-specific name. This encodes the hardware addressing information. Any given system name must be unique within the layout.- Specified by:
getSystemNamein interfaceNamedBean- Returns:
- the system-specific name
-
toString
Display the system-specific name.Note that this is a firm contract: toString() in all implementing classes must return the system name followed by optional additional information. Using code can assume that the result of toString() will always be or start with the system name followed by some kind of separator character.
-
toStringSuffix
Overload this in a sub-class to add extra info to the results of toString()- Returns:
- a suffix to add at the end of #toString() result
-
getUserName
User's identification for the item. Bound parameter so manager(s) can listen to changes. Any given user name must be unique within the layout. Must not match the system name.- Specified by:
getUserNamein interfaceNamedBean- Returns:
- null if not set
-
setUserName
@OverridingMethodsMustInvokeSuper public void setUserName(String s) throws NamedBean.BadUserNameException Set the user name, normalizing it if needed.- Specified by:
setUserNamein interfaceNamedBean- Parameters:
s- the new user name- Throws:
NamedBean.BadUserNameException- if the user name can not be normalized
-
firePropertyChange
-
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.
-
describeState
Provide human-readable, localized version of state value.This method is intended for use when presenting to a human operator.
- Specified by:
describeStatein interfaceNamedBean- Parameters:
state- the state to describe- Returns:
- the state in localized form
-
setProperty
Attach a key/value pair to the NamedBean, which can be retrieved later. These are not bound properties as yet, and don't throw events on modification. Key must not be null.The key is constrained to String to make these behave like normal Java Beans.
- Specified by:
setPropertyin interfaceNamedBean- Parameters:
key- the property to setvalue- the value of the property
-
getProperty
Retrieve the value associated with a key. If no value has been set for that key, returns null.- Specified by:
getPropertyin interfaceNamedBean- Parameters:
key- the property to get- Returns:
- The value of the property or null.
-
getPropertyKeys
Retrieve the complete current set of keys.- Specified by:
getPropertyKeysin interfaceNamedBean- Returns:
- empty set if none
-
removeProperty
Remove the key/value pair against the NamedBean.- Specified by:
removePropertyin interfaceNamedBean- Parameters:
key- the property to remove
-
vetoableChange
- Specified by:
vetoableChangein interfaceNamedBean- Throws:
PropertyVetoException
-
equals
This implementation tests that
NamedBean.getSystemName()is equal for this and obj. -
hashCode
-
compareSystemNameSuffix
@CheckReturnValue public int compareSystemNameSuffix(@Nonnull String suffix1, @Nonnull 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.- Specified by:
compareSystemNameSuffixin interfaceNamedBean- 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.
-