Class ComputedObservableMap<K,​V>

  • Type Parameters:
    K - type of the keys to the map
    V - type of the values in the map
    All Implemented Interfaces:
    java.util.Map<K,​V>, IObservable, IObservableMap<K,​V>

    public abstract class ComputedObservableMap<K,​V>
    extends AbstractObservableMap<K,​V>
    Maps objects to one of their attributes. Tracks changes to the underlying observable set of objects (keys), as well as changes to attribute values.
    • Constructor Detail

      • ComputedObservableMap

        public ComputedObservableMap​(IObservableSet<K> keySet)
        Parameters:
        keySet - the key set
      • ComputedObservableMap

        public ComputedObservableMap​(IObservableSet<K> keySet,
                                     java.lang.Object valueType)
        Parameters:
        keySet - the key set
        valueType - the value type
        Since:
        1.2
    • Method Detail

      • init

        @Deprecated
        protected void init()
        Deprecated.
        Subclasses are no longer required to call this method.
      • fireSingleChange

        protected final void fireSingleChange​(K key,
                                              V oldValue,
                                              V newValue)
      • getKeyType

        public java.lang.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>
        Overrides:
        getKeyType in class AbstractObservableMap<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 java.lang.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>
        Overrides:
        getValueType in class AbstractObservableMap<K,​V>
        Returns:
        the element type for the values of this observable map, or null if the values collection is untyped.
        Since:
        1.2
      • remove

        public V remove​(java.lang.Object key)
        Specified by:
        remove in interface IObservableMap<K,​V>
        Specified by:
        remove in interface java.util.Map<K,​V>
        Overrides:
        remove in class java.util.AbstractMap<K,​V>
        Since:
        1.3
      • containsKey

        public boolean containsKey​(java.lang.Object key)
        Specified by:
        containsKey in interface IObservableMap<K,​V>
        Specified by:
        containsKey in interface java.util.Map<K,​V>
        Overrides:
        containsKey in class java.util.AbstractMap<K,​V>
        Since:
        1.3
      • entrySet

        public java.util.Set<java.util.Map.Entry<K,​V>> entrySet()
        Specified by:
        entrySet in interface IObservableMap<K,​V>
        Specified by:
        entrySet in interface java.util.Map<K,​V>
        Specified by:
        entrySet in class java.util.AbstractMap<K,​V>
      • keySet

        public java.util.Set<K> keySet()
        Specified by:
        keySet in interface IObservableMap<K,​V>
        Specified by:
        keySet in interface java.util.Map<K,​V>
        Overrides:
        keySet in class java.util.AbstractMap<K,​V>
      • get

        public final V get​(java.lang.Object key)
        Specified by:
        get in interface IObservableMap<K,​V>
        Specified by:
        get in interface java.util.Map<K,​V>
        Overrides:
        get in class java.util.AbstractMap<K,​V>
      • put

        public final V put​(K key,
                           V value)
        Specified by:
        put in interface IObservableMap<K,​V>
        Specified by:
        put in interface java.util.Map<K,​V>
        Overrides:
        put in class java.util.AbstractMap<K,​V>
      • unhookListener

        protected abstract void unhookListener​(K removedKey)
        Parameters:
        removedKey - element to remove listener from
      • hookListener

        protected abstract void hookListener​(K addedKey)
        Parameters:
        addedKey - element to add listener to
      • doGet

        protected abstract V doGet​(K key)
        Parameters:
        key - the key
        Returns:
        the value for the given key
      • doPut

        protected abstract V doPut​(K key,
                                   V value)
        Parameters:
        key - the key
        value - key's new value
        Returns:
        the old value for the given key
      • 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
        Overrides:
        isStale in class AbstractObservableMap<K,​V>
        Returns:
        true if this observable's state is stale and will change soon.
      • 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
        Overrides:
        dispose in class AbstractObservableMap<K,​V>