Package com.norconex.commons.lang.map

# Class MapChangeSupport<K,V>

java.lang.Object
com.norconex.commons.lang.map.MapChangeSupport<K,V>

Type Parameters:
  `K` - the type of keys maintained by the map we are observing
  `V` - the type of mapped values

public class MapChangeSupport<K,V> extends Object
Here is an example of `MapChangeSupport` usage:

     public class MyMap extends Map {
         private final MapChangeSupport mcs = new MapChangeSupport(this);

         public void addMapChangeListener(MapChangeListener listener) {
             this.mcs.addMapChangeListener(listener);
         }

         public void removeMapChangeListener(MapChangeListener listener) {
             this.mcs.removeMapChangeListener(listener);
         }

         public Object put(Object key, Object value) {
             Object oldValue = map.put(key, value);
             mcs.fireMapChange(key, oldValue, value);
             return oldValue;
         }

         [...]
     }

Since:
  1.4

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `MapChangeSupport(Map<K,V> source)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `addMapChangeListener(MapChangeListener<K,V> listener)`
  Add a `MapChangeListener` to the listener list.
  `protected boolean`
  `canEqual(Object other)`
  `void`
  `clear()`
  Clears the listeners associated with this instance.
  `boolean`
  `equals(Object o)`
  `void`
  `fireMapChange(K key, V oldValue, V newValue)`
  Fires a `MapChangeEvent` to all change listeners.
  `List<MapChangeListener<K,V>>`
  `getMapChangeListeners()`
  Gets an unmodifiable list of listeners.
  `int`
  `hashCode()`
  `boolean`
  `isEmpty()`
  Gets whether this instance has no listeners.
  `void`
  `removeMapChangeListener(MapChangeListener<K,V> listener)`
  Removes a `MapChangeListener` from the listener list.
  `String`
  `toString()`

  ### Methods inherited from class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### MapChangeSupport

    public MapChangeSupport(Map<K,V> source)

- ## Method Details

  - ### addMapChangeListener

    public void addMapChangeListener(MapChangeListener<K,V> listener)
    Add a `MapChangeListener` to the listener list. If `listener` is null, no exception is thrown and no action is taken.
    Parameters:
      `listener` - The `MapChangeListener` to be added

  - ### removeMapChangeListener

    public void removeMapChangeListener(MapChangeListener<K,V> listener)
    Removes a `MapChangeListener` from the listener list. If `listener` is null, no exception is thrown and no action is taken.
    Parameters:
      `listener` - The `MapChangeListener` to be removed

  - ### getMapChangeListeners

    public List<MapChangeListener<K,V>> getMapChangeListeners()
    Gets an unmodifiable list of listeners.
    Returns:
      listeners
    Since:
      3.0.0

  - ### clear

    public void clear()
    Clears the listeners associated with this instance.
    Since:
      3.0.0

  - ### fireMapChange

    public void fireMapChange(K key, V oldValue, V newValue)
    Fires a `MapChangeEvent` to all change listeners.
    Parameters:
      `key` - the key for the value change
      `oldValue` - the old value
      `newValue` - the new value

  - ### isEmpty

    public boolean isEmpty()
    Gets whether this instance has no listeners.
    Returns:
      `true` if there are no listeners

  - ### toString

    public String toString()
    Overrides:
      `toString` in class `Object`

  - ### equals

    public boolean equals(Object o)
    Overrides:
      `equals` in class `Object`

  - ### canEqual

    protected boolean canEqual(Object other)

  - ### hashCode

    public int hashCode()
    Overrides:
      `hashCode` in class `Object`