Class WritableMap<K,​V>

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

    public class WritableMap<K,​V>
    extends ObservableMap<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

      • WritableMap

        public WritableMap()
        Constructs a new WritableMap on the default realm.
      • WritableMap

        public WritableMap​(Realm realm)
        Constructs a new WritableMap on the given realm.
        Parameters:
        realm - the realm
      • WritableMap

        public WritableMap​(Object keyType,
                           Object valueType)
        Constructs a new WritableMap on the default realm with the specified key and value types.
        Parameters:
        keyType - the type of the keys in this map
        valueType - the type of the values in this map
        Since:
        1.2
      • WritableMap

        public WritableMap​(Realm realm,
                           Object keyType,
                           Object valueType)
        Constructs a new WritableMap on the given realm with the specified key and value types.
        Parameters:
        realm - the realm
        keyType - the type of the keys in this map
        valueType - the type of the values in this map
        Since:
        1.2
    • Method Detail

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

        public V put​(K key,
                     V value)
        Associates the provided value with the key. Must be invoked from the current realm.
        Specified by:
        put in interface IObservableMap<K,​V>
        Specified by:
        put in interface Map<K,​V>
        Overrides:
        put in class ObservableMap<K,​V>
      • clear

        public void clear()
        Clears the map. Must be invoked from the current realm.
        Specified by:
        clear in interface Map<K,​V>
        Overrides:
        clear in class ObservableMap<K,​V>
      • putAll

        public void putAll​(Map<? extends K,​? extends V> map)
        Adds the provided map's contents to this map. Must be invoked from the current realm.
        Specified by:
        putAll in interface Map<K,​V>
        Overrides:
        putAll in class ObservableMap<K,​V>
      • addListener

        protected void addListener​(Object listenerType,
                                   IObservablesListener listener)
        Parameters:
        listenerType - arbitrary object to identify a type of the listener
        listener - the listener to add; not null
      • removeListener

        protected void removeListener​(Object listenerType,
                                      IObservablesListener listener)
        Parameters:
        listenerType - arbitrary object to identify a type of the listener
        listener - the listener to remove; not null
      • hasListeners

        protected boolean hasListeners()
      • firstListenerAdded

        protected void firstListenerAdded()
      • lastListenerRemoved

        protected void lastListenerRemoved()
      • getRealm

        public Realm getRealm()
        Returns:
        Returns the realm.