|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.util.AbstractMap
com.taco.data.AbstractNoReturnMap
com.taco.data.ObservableMap
public class ObservableMap
A concrete implementation of IObservableMap
.
This class decorates another map which provides the storage. If the the
decorated map is an instance of INoReturnMap
, this class will
call putNoReturn()
and removeNoReturn()
on the
decorated map instead of put()
and remove()
whenever possible.
This class attempts to prevent infinite recursion in the following
situation: When a single thread calls put(key, value, true)
, a
listener is notified of a change on the same thread. The listener attempts
to put the same value in the map again. (This might happen if the listener
updates a component, and on update the component notifies its listeners.
One of its listeners might be a map consistency listener which updates the
map in response to the component property change). Thus the recursion cycle
is complete. This class breaks the cycle by keeping track of the keys that
are being put at any given time. Before the value associated with a key is
changed, the key is added to a put key set. If during the notification of
listeners, someone attempts to put the same key in the map (with
any value), the put operation will silently return without doing
anything. This only works if everything occurs in the same thread. If this
is not the case, it is up to listeners to detect infinite recursion and
break the recursion cycle.
This class is not safe for use by multiple threads.
Nested Class Summary | |
---|---|
protected class |
ObservableMap.EntrySet
The set used as the entry set of the map. |
protected static class |
ObservableMap.ValueElement
The data structure that is used for map values. |
Nested classes/interfaces inherited from class com.taco.data.AbstractNoReturnMap |
---|
AbstractNoReturnMap.NoReturnEntry, AbstractNoReturnMap.NoReturnEntrySet, AbstractNoReturnMap.NoReturnIterator |
Nested classes/interfaces inherited from interface com.taco.data.INoReturnObservableMap |
---|
INoReturnObservableMap.INoReturnObservableEntry |
Nested classes/interfaces inherited from interface com.taco.data.INoReturnMap |
---|
INoReturnMap.INoReturnEntry |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry |
Nested classes/interfaces inherited from interface com.taco.data.IObservableMap |
---|
IObservableMap.IObservableEntry |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry |
Field Summary | |
---|---|
protected java.util.Set |
_cachedEntrySet
The entry set, lazily computed and cached. |
protected java.util.Map |
_map
The map that provides the underlying storage. |
protected IMapFactory |
_mapFactory
The factory used to create new maps and copies of maps. |
protected INoReturnMap |
_noReturnMap
If _map is an instance of INoReturnMap , this
is a casted copy of _map . |
protected INotificationStrategy |
_notificationStrategy
The strategy that specifies how to notify listeners. |
protected java.util.Collection |
_putKeys
A set of keys that have been put so far in the current call stack. |
Fields inherited from class com.taco.data.AbstractNoReturnMap |
---|
_cachedNoReturnEntrySet |
Fields inherited from interface com.taco.data.IObservableMap |
---|
SINGLE_THREADED_STRATEGY |
Constructor Summary | |
---|---|
|
ObservableMap()
Create a new instance that uses a hash map factory, with a initial size of 16 entries, and a single-threaded notification strategy. |
|
ObservableMap(IMapFactory mapFactory,
int capacity,
INotificationStrategy notificationStrategy)
Construct a new instance that uses the argument factory to create a new map that provides storage for the new instance. |
|
ObservableMap(INotificationStrategy notificationStrategy)
Create a new instance that uses a hash map factory, with a initial size of 16 entries, and the argument notification strategy. |
|
ObservableMap(java.util.Map map)
Create a new instance that uses a hash map factory to make a copy of the argument map and a single-threaded notification strategy. |
|
ObservableMap(java.util.Map map,
IMapFactory mapFactory,
INotificationStrategy notificationStrategy)
|
protected |
ObservableMap(ObservableMap observableMap)
Create a new instance that uses a clone of the argument map's storage map for its own storage. |
Method Summary | |
---|---|
protected void |
_notifyListeners(java.lang.Object key,
java.lang.Object oldValue,
java.lang.Object newValue,
java.util.Collection listeners,
IObjectFilter listenerFilter)
Notify all listeners of the change in the value mapped to the argument key. |
void |
addPropertyChangeListener(java.lang.String key,
java.beans.PropertyChangeListener listener)
Add listener to the list of listeners for changes to the value mapped to key . |
void |
clear()
|
java.lang.Object |
clone()
|
boolean |
containsKey(java.lang.Object key)
|
boolean |
containsValue(java.lang.Object value)
|
java.util.Set |
entrySet()
|
java.lang.Object |
get(java.lang.Object key)
|
INotificationStrategy |
getNotificationStrategy()
Return the strategy used to notify listeners. |
java.util.Collection |
getPropertyChangeListeners(java.lang.String key)
Return a collection of the property change listeners for the argument key. |
boolean |
isEmpty()
|
java.util.Set |
keySet()
|
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
Call put(key, value, AcceptAllObjectFilter.instance)
(notify all listeners). |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
boolean notifyListeners)
Associate value with key in the map. |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value,
IObjectFilter listenerFilter)
Put the key-value pair in the map. |
void |
putAll(java.util.Map sourceMap)
Call putAll(sourceMap, true) (notify listeners). |
void |
putAll(java.util.Map sourceMap,
boolean notifyListeners)
Put all key / value pairs in the argument map in this map. |
void |
putAll(java.util.Map sourceMap,
IObjectFilter filter)
Copy all of the mappings from the specified map to this map. |
void |
putNoReturn(java.lang.Object key,
java.lang.Object value)
Call putNoReturn(key, value, true) (notify all listeners). |
void |
putNoReturn(java.lang.Object key,
java.lang.Object value,
boolean notifyListeners)
Associate value with key in the map. |
void |
putNoReturn(java.lang.Object key,
java.lang.Object value,
IObjectFilter listenerFilter)
|
java.lang.Object |
remove(java.lang.Object key)
|
void |
removeNoReturn(java.lang.Object key)
This implementation simply calls remove() -- there is
no speed advantage to using this method. |
void |
removePropertyChangeListener(java.lang.String key,
java.beans.PropertyChangeListener listener)
If listener is a listener for the argument key, remove it
from the list of listeners for the key. |
void |
setNotificationStrategy(INotificationStrategy strategy)
Set the strategy used to notify listeners. |
void |
setPropertyChangeListeners(java.lang.String key,
java.util.Collection listeners)
Set the collection of listeners to be notified when the value associated with key is changed. |
int |
size()
|
Methods inherited from class com.taco.data.AbstractNoReturnMap |
---|
entrySetNoReturn |
Methods inherited from class java.util.AbstractMap |
---|
equals, hashCode, toString, values |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface com.taco.data.INoReturnMap |
---|
entrySetNoReturn |
Methods inherited from interface java.util.Map |
---|
equals, hashCode, values |
Methods inherited from interface java.util.Map |
---|
equals, hashCode, values |
Field Detail |
---|
protected IMapFactory _mapFactory
protected java.util.Map _map
protected INoReturnMap _noReturnMap
_map
is an instance of INoReturnMap
, this
is a casted copy of _map
.
protected INotificationStrategy _notificationStrategy
protected java.util.Collection _putKeys
protected transient java.util.Set _cachedEntrySet
Constructor Detail |
---|
public ObservableMap()
public ObservableMap(INotificationStrategy notificationStrategy)
public ObservableMap(IMapFactory mapFactory, int capacity, INotificationStrategy notificationStrategy)
public ObservableMap(java.util.Map map)
public ObservableMap(java.util.Map map, IMapFactory mapFactory, INotificationStrategy notificationStrategy)
protected ObservableMap(ObservableMap observableMap)
Method Detail |
---|
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.util.AbstractMap
java.lang.CloneNotSupportedException
public void clear()
clear
in interface java.util.Map
clear
in class java.util.AbstractMap
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map
containsKey
in class java.util.AbstractMap
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map
containsValue
in class java.util.AbstractMap
public java.util.Set entrySet()
entrySet
in interface java.util.Map
entrySet
in class java.util.AbstractMap
public java.lang.Object get(java.lang.Object key)
get
in interface java.util.Map
get
in class java.util.AbstractMap
public boolean isEmpty()
isEmpty
in interface java.util.Map
isEmpty
in class java.util.AbstractMap
public java.util.Set keySet()
keySet
in interface java.util.Map
keySet
in class java.util.AbstractMap
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put(key, value, AcceptAllObjectFilter.instance)
(notify all listeners).
put
in interface IObservableMap
put
in interface java.util.Map
put
in class java.util.AbstractMap
public void putNoReturn(java.lang.Object key, java.lang.Object value)
putNoReturn(key, value, true)
(notify all listeners).
putNoReturn
in interface INoReturnMap
putNoReturn
in class AbstractNoReturnMap
public java.lang.Object put(java.lang.Object key, java.lang.Object value, boolean notifyListeners)
value
with key
in the map.
If there are any listeners of changes to the values mapped by the
argument key, notify them via _notifyListeners()
.
If the value is being put already somewhere in the call stack,
return null
.
put
in interface IObservableMap
notifyListeners
- If true, notify listeners of the change.public java.lang.Object put(java.lang.Object key, java.lang.Object value, IObjectFilter listenerFilter)
IObservableMap
put
in interface IObservableMap
public void putNoReturn(java.lang.Object key, java.lang.Object value, boolean notifyListeners)
value
with key
in the map.
If there are any listeners of changes to the values mapped by the
argument key, notify them via _notifyListeners()
.
putNoReturn
in interface INoReturnObservableMap
notifyListeners
- If true, notify listeners of the change.public void putNoReturn(java.lang.Object key, java.lang.Object value, IObjectFilter listenerFilter)
putNoReturn
in interface INoReturnObservableMap
public void putAll(java.util.Map sourceMap)
putAll(sourceMap, true)
(notify listeners).
putAll
in interface INoReturnMap
putAll
in interface IObservableMap
putAll
in interface java.util.Map
putAll
in class AbstractNoReturnMap
java.lang.NullPointerException
- if sourceMap
is
null
.public void putAll(java.util.Map sourceMap, boolean notifyListeners)
putAll
in interface IObservableMap
notifyListeners
- If true, notify listeners of the change.
java.lang.NullPointerException
- if sourceMap
is
null
.public void putAll(java.util.Map sourceMap, IObjectFilter filter)
IObservableMap
notifyListeners
is true
, notify all listeners
of the affected keys that are accepted by the filter of the changes.
putAll
in interface IObservableMap
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in class java.util.AbstractMap
public void removeNoReturn(java.lang.Object key)
AbstractNoReturnMap
remove()
-- there is
no speed advantage to using this method.
removeNoReturn
in interface INoReturnMap
removeNoReturn
in class AbstractNoReturnMap
public int size()
size
in interface java.util.Map
size
in class java.util.AbstractMap
public void addPropertyChangeListener(java.lang.String key, java.beans.PropertyChangeListener listener)
key
. If no value is mapped to key yet, map
null
to it now.
addPropertyChangeListener
in interface IObservableMap
public void removePropertyChangeListener(java.lang.String key, java.beans.PropertyChangeListener listener)
listener
is a listener for the argument key, remove it
from the list of listeners for the key. Otherwise, fail silently.
removePropertyChangeListener
in interface IObservableMap
public java.util.Collection getPropertyChangeListeners(java.lang.String key)
getPropertyChangeListeners
in interface IObservableMap
public void setPropertyChangeListeners(java.lang.String key, java.util.Collection listeners)
key
is changed. Make a copy of the
listener collection so the user is free to modify it afterwards.
setPropertyChangeListeners
in interface IObservableMap
public INotificationStrategy getNotificationStrategy()
getNotificationStrategy
in interface IObservableMap
public void setNotificationStrategy(INotificationStrategy strategy)
setNotificationStrategy
in interface IObservableMap
java.lang.NullPointerException
- if the argument strategy is
null
.protected void _notifyListeners(java.lang.Object key, java.lang.Object oldValue, java.lang.Object newValue, java.util.Collection listeners, IObjectFilter listenerFilter)
key
- The map key whose value is changed.oldValue
- The old value mapped to the key, null
if
unknown.newValue
- The new value mapped to the key.listeners
- A collection of property change listeners of the
changes to value mapped to key
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |