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 observingV- the type of mapped values
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 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddMapChangeListener(MapChangeListener<K, V> listener) Add aMapChangeListenerto the listener list.protected booleanvoidclear()Clears the listeners associated with this instance.booleanvoidfireMapChange(K key, V oldValue, V newValue) Fires aMapChangeEventto all change listeners.Gets an unmodifiable list of listeners.inthashCode()booleanisEmpty()Gets whether this instance has no listeners.voidremoveMapChangeListener(MapChangeListener<K, V> listener) Removes aMapChangeListenerfrom the listener list.toString()
-
Constructor Details
-
MapChangeSupport
-
-
Method Details
-
addMapChangeListener
Add aMapChangeListenerto the listener list. Iflisteneris null, no exception is thrown and no action is taken.- Parameters:
listener- TheMapChangeListenerto be added
-
removeMapChangeListener
Removes aMapChangeListenerfrom the listener list. Iflisteneris null, no exception is thrown and no action is taken.- Parameters:
listener- TheMapChangeListenerto be removed
-
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
Fires aMapChangeEventto all change listeners.- Parameters:
key- the key for the value changeoldValue- the old valuenewValue- the new value
-
isEmpty
public boolean isEmpty()Gets whether this instance has no listeners.- Returns:
trueif there are no listeners
-
toString
-
equals
-
canEqual
-
hashCode
public int hashCode()
-