Class AbstractObservableMap<K,​V>

  • Type Parameters:
    K - type of the keys to the map
    V - type of the values in the map
    All Implemented Interfaces:
    Map<K,​V>, IObservable, IObservableMap<K,​V>
    Direct Known Subclasses:
    ComputedObservableMap

    public abstract class AbstractObservableMap<K,​V>
    extends AbstractMap<K,​V>
    implements IObservableMap<K,​V>

    This class is thread safe. All state accessing methods must be invoked from the current realm. Methods for adding and removing listeners may be invoked from any thread.

    Since:
    1.0
    • Constructor Detail

      • AbstractObservableMap

        public AbstractObservableMap()
      • AbstractObservableMap

        public AbstractObservableMap​(Realm realm)
        Parameters:
        realm -
    • Method Detail

      • lastListenerRemoved

        protected void lastListenerRemoved()
      • firstListenerAdded

        protected void firstListenerAdded()
      • addChangeListener

        public void addChangeListener​(IChangeListener listener)
        Description copied from interface: IObservable
        Adds the given change listener to the list of change listeners. Change listeners are notified about changes of the state of this observable in a generic way, without specifying the change that happened. To get the changed state, a change listener needs to query for the current state of this observable.
        Specified by:
        addChangeListener in interface IObservable
      • addStaleListener

        public void addStaleListener​(IStaleListener listener)
        Description copied from interface: IObservable
        Adds the given stale listener to the list of stale listeners. Stale listeners are notified when an observable object becomes stale, not when is becomes non-stale.
        Specified by:
        addStaleListener in interface IObservable
        See Also:
        IObservable.isStale()
      • hasListeners

        protected boolean hasListeners()
        Returns:
        whether the observable map has listeners registered
        Since:
        1.2
      • addDisposeListener

        public void addDisposeListener​(IDisposeListener listener)
        Description copied from interface: IObservable
        Adds the given dispose listener to the list of dispose listeners. Dispose listeners are notified when an observable has been disposed.
        Specified by:
        addDisposeListener in interface IObservable
        Parameters:
        listener - the listener to add
        Since:
        1.2
      • removeDisposeListener

        public void removeDisposeListener​(IDisposeListener listener)
        Description copied from interface: IObservable
        Removes the given dispose listener from the list of dispose listeners. Has no effect if the given listener is not registered as a dispose listener.
        Specified by:
        removeDisposeListener in interface IObservable
        Parameters:
        listener - the listener to remove
        Since:
        1.2
      • isDisposed

        public boolean isDisposed()
        Description copied from interface: IObservable
        Returns whether the observable has been disposed
        Specified by:
        isDisposed in interface IObservable
        Returns:
        whether the observable has been disposed
        Since:
        1.2
      • dispose

        public void dispose()
        Description copied from interface: IObservable
        Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.
        Specified by:
        dispose in interface IObservable
      • getRealm

        public Realm getRealm()
        Description copied from interface: IObservable
        Returns the realm for this observable. Unless otherwise specified, getters and setters must be accessed from within this realm. Listeners will be within this realm when they receive events from this observable.

        Because observables can only be accessed from within one realm, and they always fire events on that realm, their state can be observed in an incremental way. It is always safe to call getters of an observable from within a change listener attached to that observable.

        Specified by:
        getRealm in interface IObservable
        Returns:
        the realm
      • isStale

        public boolean isStale()
        Description copied from interface: IObservable
        Returns whether the state of this observable is stale and is expected to change soon. A non-stale observable that becomes stale will notify its stale listeners. A stale object that becomes non-stale does so by changing its state and notifying its change listeners, it does not notify its stale listeners about becoming non-stale. Clients that do not expect asynchronous changes may ignore staleness of observable objects.
        Specified by:
        isStale in interface IObservable
        Returns:
        true if this observable's state is stale and will change soon.
      • getKeyType

        public Object getKeyType()
        Description copied from interface: IObservableMap
        Returns the element type for the keyset of this observable map, or null if the keyset is untyped.
        Specified by:
        getKeyType in interface IObservableMap<K,​V>
        Returns:
        the element type for the keyset of this observable map, or null if the keyset is untyped.
        Since:
        1.2
      • getValueType

        public Object getValueType()
        Description copied from interface: IObservableMap
        Returns the element type for the values of this observable map, or null if the values collection is untyped.
        Specified by:
        getValueType in interface IObservableMap<K,​V>
        Returns:
        the element type for the values of this observable map, or null if the values collection is untyped.
        Since:
        1.2
      • removeChangeListener

        public void removeChangeListener​(IChangeListener listener)
        Description copied from interface: IObservable
        Removes the given change listener from the list of change listeners. Has no effect if the given listener is not registered as a change listener.
        Specified by:
        removeChangeListener in interface IObservable
      • removeStaleListener

        public void removeStaleListener​(IStaleListener listener)
        Description copied from interface: IObservable
        Removes the given stale listener from the list of stale listeners. Has no effect if the given listener is not registered as a stale listener.
        Specified by:
        removeStaleListener in interface IObservable
      • setStale

        public void setStale​(boolean stale)
        Sets the stale state. Must be invoked from the current realm.
        Parameters:
        stale -
      • fireStale

        protected void fireStale()
        Fires stale events. Must be invoked from current realm.
      • fireChange

        protected void fireChange()
        Fires change events. Must be invoked from current realm.
      • fireMapChange

        protected void fireMapChange​(MapDiff<K,​V> diff)
        Fires map change events. Must be invoked from current realm.
        Parameters:
        diff -