Class AbstractObservableMap<K,V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- org.eclipse.core.databinding.observable.map.AbstractObservableMap<K,V>
-
- Type Parameters:
K
- type of the keys to the mapV
- type of the values in the map
- All Implemented Interfaces:
Map<K,V>
,IObservable
,IObservableMap<K,V>
- Direct Known Subclasses:
ComputedObservableMap
public abstract class AbstractObservableMap<K,V> extends AbstractMap<K,V> implements IObservableMap<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
- Implementation Note:
- If methods are added to the interface which this class implements then implementations of those methods must be added to this class.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description AbstractObservableMap()
AbstractObservableMap(Realm realm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChangeListener(IChangeListener listener)
Adds the given change listener to the list of change listeners.void
addDisposeListener(IDisposeListener listener)
Adds the given dispose listener to the list of dispose listeners.void
addMapChangeListener(IMapChangeListener<? super K,? super V> listener)
void
addStaleListener(IStaleListener listener)
Adds the given stale listener to the list of stale listeners.protected void
checkRealm()
Asserts that the realm is the current realm.void
dispose()
Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.protected void
fireChange()
Fires change events.protected void
fireMapChange(MapDiff<K,V> diff)
Fires map change events.protected void
fireStale()
Fires stale events.protected void
firstListenerAdded()
Object
getKeyType()
Returns the element type for thekeyset
of this observable map, ornull
if the keyset is untyped.Realm
getRealm()
Returns the realm for this observable.Object
getValueType()
Returns the element type for thevalues
of this observable map, ornull
if the values collection is untyped.protected boolean
hasListeners()
boolean
isDisposed()
Returns whether the observable has been disposedboolean
isStale()
Returns whether the state of this observable is stale and is expected to change soon.protected void
lastListenerRemoved()
void
removeChangeListener(IChangeListener listener)
Removes the given change listener from the list of change listeners.void
removeDisposeListener(IDisposeListener listener)
Removes the given dispose listener from the list of dispose listeners.void
removeMapChangeListener(IMapChangeListener<? super K,? super V> listener)
void
removeStaleListener(IStaleListener listener)
Removes the given stale listener from the list of stale listeners.void
setStale(boolean stale)
Sets the stale state.-
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, putAll, remove, size, toString, values
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.core.databinding.observable.map.IObservableMap
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, put, remove, size, values
-
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putAll, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
AbstractObservableMap
public AbstractObservableMap()
-
AbstractObservableMap
public AbstractObservableMap(Realm realm)
- Parameters:
realm
- the realm; notnull
-
-
Method Detail
-
lastListenerRemoved
protected void lastListenerRemoved()
-
firstListenerAdded
protected void firstListenerAdded()
-
addMapChangeListener
public void addMapChangeListener(IMapChangeListener<? super K,? super V> listener)
- Specified by:
addMapChangeListener
in interfaceIObservableMap<K,V>
- Parameters:
listener
- the change listener to add; notnull
-
removeMapChangeListener
public void removeMapChangeListener(IMapChangeListener<? super K,? super V> listener)
- Specified by:
removeMapChangeListener
in interfaceIObservableMap<K,V>
- Parameters:
listener
- the change listener to remove; notnull
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Description copied from interface:IObservable
Adds the given change listener to the list of change listeners. Change listeners are notified about changes of the state of this observable in a generic way, without specifying the change that happened. To get the changed state, a change listener needs to query for the current state of this observable.- Specified by:
addChangeListener
in interfaceIObservable
- Parameters:
listener
- the listener to add; notnull
-
addStaleListener
public void addStaleListener(IStaleListener listener)
Description copied from interface:IObservable
Adds the given stale listener to the list of stale listeners. Stale listeners are notified when an observable object becomes stale, not when is becomes non-stale.- Specified by:
addStaleListener
in interfaceIObservable
- Parameters:
listener
- the listener to add; notnull
- See Also:
IObservable.isStale()
-
hasListeners
protected boolean hasListeners()
- Returns:
- whether the observable map has listeners registered
- Since:
- 1.2
-
addDisposeListener
public void addDisposeListener(IDisposeListener listener)
Description copied from interface:IObservable
Adds the given dispose listener to the list of dispose listeners. Dispose listeners are notified when an observable has been disposed.- Specified by:
addDisposeListener
in interfaceIObservable
- Parameters:
listener
- the listener to add- Since:
- 1.2
-
removeDisposeListener
public void removeDisposeListener(IDisposeListener listener)
Description copied from interface:IObservable
Removes the given dispose listener from the list of dispose listeners. Has no effect if the given listener is not registered as a dispose listener.- Specified by:
removeDisposeListener
in interfaceIObservable
- Parameters:
listener
- the listener to remove- Since:
- 1.2
-
isDisposed
public boolean isDisposed()
Description copied from interface:IObservable
Returns whether the observable has been disposed- Specified by:
isDisposed
in interfaceIObservable
- Returns:
- whether the observable has been disposed
- Since:
- 1.2
-
dispose
public void dispose()
Description copied from interface:IObservable
Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.- Specified by:
dispose
in interfaceIObservable
-
getRealm
public Realm getRealm()
Description copied from interface:IObservable
Returns the realm for this observable. Unless otherwise specified, getters and setters must be accessed from within this realm. Listeners will be within this realm when they receive events from this observable.Because observables can only be accessed from within one realm, and they always fire events on that realm, their state can be observed in an incremental way. It is always safe to call getters of an observable from within a change listener attached to that observable.
- Specified by:
getRealm
in interfaceIObservable
- Returns:
- the realm
-
isStale
public boolean isStale()
Description copied from interface:IObservable
Returns whether the state of this observable is stale and is expected to change soon. A non-stale observable that becomes stale will notify its stale listeners. A stale object that becomes non-stale does so by changing its state and notifying its change listeners, it does not notify its stale listeners about becoming non-stale. Clients that do not expect asynchronous changes may ignore staleness of observable objects.- Specified by:
isStale
in interfaceIObservable
- Returns:
- true if this observable's state is stale and will change soon.
-
getKeyType
public Object getKeyType()
Description copied from interface:IObservableMap
Returns the element type for thekeyset
of this observable map, ornull
if the keyset is untyped.- Specified by:
getKeyType
in interfaceIObservableMap<K,V>
- Returns:
- the element type for the
keyset
of this observable map, ornull
if the keyset is untyped. - Since:
- 1.2
-
getValueType
public Object getValueType()
Description copied from interface:IObservableMap
Returns the element type for thevalues
of this observable map, ornull
if the values collection is untyped.- Specified by:
getValueType
in interfaceIObservableMap<K,V>
- Returns:
- the element type for the
values
of this observable map, ornull
if the values collection is untyped. - Since:
- 1.2
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Description copied from interface:IObservable
Removes the given change listener from the list of change listeners. Has no effect if the given listener is not registered as a change listener.- Specified by:
removeChangeListener
in interfaceIObservable
- Parameters:
listener
- the listener to remove; notnull
-
removeStaleListener
public void removeStaleListener(IStaleListener listener)
Description copied from interface:IObservable
Removes the given stale listener from the list of stale listeners. Has no effect if the given listener is not registered as a stale listener.- Specified by:
removeStaleListener
in interfaceIObservable
- Parameters:
listener
- the listener to remove; notnull
-
setStale
public void setStale(boolean stale)
Sets the stale state. Must be invoked from the current realm.- Parameters:
stale
- the new stale state
-
fireStale
protected void fireStale()
Fires stale events. Must be invoked from current realm.
-
fireChange
protected void fireChange()
Fires change events. Must be invoked from current realm.
-
fireMapChange
protected void fireMapChange(MapDiff<K,V> diff)
Fires map change events. Must be invoked from current realm.- Parameters:
diff
- the change
-
checkRealm
protected void checkRealm()
Asserts that the realm is the current realm.- Throws:
AssertionFailedException
- if the realm is not the current realm- See Also:
Realm.isCurrent()
-
-