Package groovy.util
Class ObservableMap
java.lang.Object
groovy.util.ObservableMap
- All Implemented Interfaces:
- java.util.Map
public class ObservableMap
extends java.lang.Object
implements java.util.Map
Map decorator that will trigger PropertyChangeEvents when a value changes.
An optional Closure may be specified and will work as a filter, if it returns true the property will trigger an event (if the value indeed changed), otherwise it won't. The Closure may receive 1 or 2 parameters, the single one being the value, the other one both the key and value, for example:
An optional Closure may be specified and will work as a filter, if it returns true the property will trigger an event (if the value indeed changed), otherwise it won't. The Closure may receive 1 or 2 parameters, the single one being the value, the other one both the key and value, for example:
 // skip all properties whose value is a closure
 def map = new ObservableMap( {!(it instanceof Closure)} )
 // skip all properties whose name matches a regex
 def map = new ObservableMap( { name, value -> !(name =~ /[A-Z+]/) } )
 
 The current implementation will trigger specialized events in the following scenarios,
 you need not register a different listener as those events extend from PropertyChangeEvent
 - ObservableMap.PropertyAddedEvent - a new property is added to the map
- ObservableMap.PropertyRemovedEvent - a property is removed from the map
- ObservableMap.PropertyUpdatedEvent - a property changes value (same as regular PropertyChangeEvent)
- ObservableMap.PropertyClearedEvent - all properties have been removed from the map
- ObservableMap.MultiPropertyEvent - triggered by calling map.putAll(), contains Added|Updated events
Bound properties
- content - read-only.
- size - read-only.
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classObservableMap.ChangeTypestatic classObservableMap.MultiPropertyEventstatic classObservableMap.PropertyAddedEventstatic classObservableMap.PropertyClearedEventstatic classObservableMap.PropertyEventstatic classObservableMap.PropertyRemovedEventstatic classObservableMap.PropertyUpdatedEventNested classes/interfaces inherited from interface java.util.Mapjava.util.Map.Entry<K extends java.lang.Object,V extends java.lang.Object>
- 
Field SummaryFields Modifier and Type Field Description static java.lang.StringCLEARED_PROPERTYstatic java.lang.StringCONTENT_PROPERTYstatic java.lang.StringSIZE_PROPERTY
- 
Constructor SummaryConstructors Constructor Description ObservableMap()ObservableMap(Closure test)ObservableMap(java.util.Map delegate)ObservableMap(java.util.Map delegate, Closure test)
- 
Method SummaryModifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)voidaddPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)voidclear()booleancontainsKey(java.lang.Object key)booleancontainsValue(java.lang.Object value)java.util.SetentrySet()booleanequals(java.lang.Object o)protected voidfireMultiPropertyEvent(ObservableMap.PropertyEvent[] events)protected voidfireMultiPropertyEvent(java.util.List<ObservableMap.PropertyEvent> events)protected voidfirePropertyAddedEvent(java.lang.Object key, java.lang.Object value)protected voidfirePropertyClearedEvent(java.util.Map values)protected voidfirePropertyEvent(ObservableMap.PropertyEvent event)protected voidfirePropertyRemovedEvent(java.lang.Object key, java.lang.Object value)protected voidfirePropertyUpdatedEvent(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)protected voidfireSizeChangedEvent(int oldValue, int newValue)java.lang.Objectget(java.lang.Object key)java.util.MapgetContent()protected java.util.MapgetMapDelegate()java.beans.PropertyChangeListener[]getPropertyChangeListeners()java.beans.PropertyChangeListener[]getPropertyChangeListeners(java.lang.String propertyName)intgetSize()protected ClosuregetTest()inthashCode()booleanhasListeners(java.lang.String propertyName)booleanisEmpty()java.util.SetkeySet()java.lang.Objectput(java.lang.Object key, java.lang.Object value)voidputAll(java.util.Map map)java.lang.Objectremove(java.lang.Object key)voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)voidremovePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)intsize()java.util.Collectionvalues()Methods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Mapcompute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
- 
Field Details- 
SIZE_PROPERTYpublic static final java.lang.String SIZE_PROPERTY- See Also:
- Constant Field Values
 
- 
CONTENT_PROPERTYpublic static final java.lang.String CONTENT_PROPERTY- See Also:
- Constant Field Values
 
- 
CLEARED_PROPERTYpublic static final java.lang.String CLEARED_PROPERTY- See Also:
- Constant Field Values
 
 
- 
- 
Constructor Details- 
ObservableMappublic ObservableMap()
- 
ObservableMap
- 
ObservableMappublic ObservableMap(java.util.Map delegate)
- 
ObservableMap
 
- 
- 
Method Details- 
getMapDelegateprotected java.util.Map getMapDelegate()
- 
getTest
- 
getContentpublic java.util.Map getContent()
- 
firePropertyClearedEventprotected void firePropertyClearedEvent(java.util.Map values)
- 
firePropertyAddedEventprotected void firePropertyAddedEvent(java.lang.Object key, java.lang.Object value)
- 
firePropertyUpdatedEventprotected void firePropertyUpdatedEvent(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue)
- 
fireMultiPropertyEvent
- 
fireMultiPropertyEvent
- 
firePropertyRemovedEventprotected void firePropertyRemovedEvent(java.lang.Object key, java.lang.Object value)
- 
firePropertyEvent
- 
fireSizeChangedEventprotected void fireSizeChangedEvent(int oldValue, int newValue)
- 
clearpublic void clear()- Specified by:
- clearin interface- java.util.Map
 
- 
containsKeypublic boolean containsKey(java.lang.Object key)- Specified by:
- containsKeyin interface- java.util.Map
 
- 
containsValuepublic boolean containsValue(java.lang.Object value)- Specified by:
- containsValuein interface- java.util.Map
 
- 
entrySetpublic java.util.Set entrySet()- Specified by:
- entrySetin interface- java.util.Map
 
- 
equalspublic boolean equals(java.lang.Object o)- Specified by:
- equalsin interface- java.util.Map
- Overrides:
- equalsin class- java.lang.Object
 
- 
getpublic java.lang.Object get(java.lang.Object key)- Specified by:
- getin interface- java.util.Map
 
- 
hashCodepublic int hashCode()- Specified by:
- hashCodein interface- java.util.Map
- Overrides:
- hashCodein class- java.lang.Object
 
- 
isEmptypublic boolean isEmpty()- Specified by:
- isEmptyin interface- java.util.Map
 
- 
keySetpublic java.util.Set keySet()- Specified by:
- keySetin interface- java.util.Map
 
- 
putpublic java.lang.Object put(java.lang.Object key, java.lang.Object value)- Specified by:
- putin interface- java.util.Map
 
- 
putAllpublic void putAll(java.util.Map map)- Specified by:
- putAllin interface- java.util.Map
 
- 
removepublic java.lang.Object remove(java.lang.Object key)- Specified by:
- removein interface- java.util.Map
 
- 
sizepublic int size()- Specified by:
- sizein interface- java.util.Map
 
- 
getSizepublic int getSize()
- 
valuespublic java.util.Collection values()- Specified by:
- valuesin interface- java.util.Map
 
- 
addPropertyChangeListenerpublic void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
- 
addPropertyChangeListenerpublic void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
- 
getPropertyChangeListenerspublic java.beans.PropertyChangeListener[] getPropertyChangeListeners()
- 
getPropertyChangeListenerspublic java.beans.PropertyChangeListener[] getPropertyChangeListeners(java.lang.String propertyName)
- 
removePropertyChangeListenerpublic void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
- 
removePropertyChangeListenerpublic void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)
- 
hasListenerspublic boolean hasListeners(java.lang.String propertyName)
 
-