Class AbstractNamedBean

    • Field Detail

      • mSystemName

        protected final java.lang.String mSystemName
      • register

        protected final java.util.HashMap<java.beans.PropertyChangeListener,​java.lang.String> register
      • listenerRefs

        protected final java.util.HashMap<java.beans.PropertyChangeListener,​java.lang.String> listenerRefs
    • Method Detail

      • getComment

        public final java.lang.String getComment()
        Get associated comment text.
        Specified by:
        getComment in interface NamedBean
        Returns:
        the comment or null
      • setComment

        public final void setComment​(java.lang.String comment)
        Set associated comment text.

        Comments can be any valid text.

        Specified by:
        setComment in interface NamedBean
        Parameters:
        comment - the comment or null to remove an existing comment
      • addPropertyChangeListener

        @OverridingMethodsMustInvokeSuper
        public void addPropertyChangeListener​(@Nonnull
                                              java.beans.PropertyChangeListener l,
                                              java.lang.String beanRef,
                                              java.lang.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:
        addPropertyChangeListener in interface NamedBean
        Parameters:
        l - The listener. This may change in the future to be a subclass of NamedProprtyChangeListener that carries the name and listenerRef values internally
        beanRef - 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 another
        listenerRef - A textual reference for the listener, that can be presented to the user when a delete is called
      • addPropertyChangeListener

        @OverridingMethodsMustInvokeSuper
        public void addPropertyChangeListener​(@Nonnull
                                              java.lang.String propertyName,
                                              @Nonnull
                                              java.beans.PropertyChangeListener l,
                                              java.lang.String beanRef,
                                              java.lang.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:
        addPropertyChangeListener in interface NamedBean
        Parameters:
        propertyName - The name of the property to listen to
        l - The listener. This may change in the future to be a subclass of NamedProprtyChangeListener that carries the name and listenerRef values internally
        beanRef - 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 another
        listenerRef - A textual reference for the listener, that can be presented to the user when a delete is called
      • getListenerRefs

        public java.util.ArrayList<java.lang.String> getListenerRefs()
        Get a meaningful list of places where the bean is in use.
        Specified by:
        getListenerRefs in interface NamedBean
        Returns:
        ArrayList of the listeners
      • getListenerRef

        public java.lang.String getListenerRef​(java.beans.PropertyChangeListener l)
        Description copied from interface: NamedBean
        Get the textual reference for the specific listener
        Specified by:
        getListenerRef in interface NamedBean
        Parameters:
        l - the listener of interest
        Returns:
        the textual reference
      • getPropertyChangeListeners

        @Nonnull
        public java.beans.PropertyChangeListener[] getPropertyChangeListeners​(java.lang.String propertyName)
        Get all PropertyChangeListeners currently listening to changes to the specified property.
        Specified by:
        getPropertyChangeListeners in interface PropertyChangeProvider
        Parameters:
        propertyName - the name of the property of interest
        Returns:
        an array of PropertyChangeListeners
      • getSystemName

        @Nonnull
        public final java.lang.String getSystemName()
        Get a system-specific name. This encodes the hardware addressing information. Any given system name must be unique within the layout.
        Specified by:
        getSystemName in interface NamedBean
        Returns:
        the system-specific name
      • toString

        @Nonnull
        public final java.lang.String 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.

        Specified by:
        toString in interface NamedBean
        Overrides:
        toString in class java.lang.Object
        Returns:
        the system-specific name
      • toStringSuffix

        protected java.lang.String 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

        public final java.lang.String 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:
        getUserName in interface NamedBean
        Returns:
        null if not set
      • 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 interface NamedBean
      • describeState

        @Nonnull
        public java.lang.String describeState​(int state)
        Provide human-readable, localized version of state value.

        This method is intended for use when presenting to a human operator.

        Specified by:
        describeState in interface NamedBean
        Parameters:
        state - the state to describe
        Returns:
        the state in localized form
      • setProperty

        @OverridingMethodsMustInvokeSuper
        public void setProperty​(@Nonnull
                                java.lang.String key,
                                java.lang.Object value)
        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.

        Prior to JMRI 4.3, the key was of Object type. It was constrained to String to make these more like normal Java Beans.

        Specified by:
        setProperty in interface NamedBean
        Parameters:
        key - the property to set
        value - the value of the property
      • vetoableChange

        public void vetoableChange​(java.beans.PropertyChangeEvent evt)
                            throws java.beans.PropertyVetoException
        Specified by:
        vetoableChange in interface NamedBean
        Throws:
        java.beans.PropertyVetoException
      • equals

        public boolean equals​(java.lang.Object obj)

        This implementation tests that NamedBean.getSystemName() is equal for this and obj.

        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the reference object with which to compare.
        Returns:
        true if this object is the same as the obj argument; false otherwise.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        hash code value is based on sthe ystem name.
      • 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 the NamedBean.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:
        compareSystemNameSuffix in interface NamedBean
        Parameters:
        suffix1 - The suffix for the 1st bean in the comparison
        suffix2 - The suffix for the 2nd bean in the comparison
        n - 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.