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
-
-
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 voidaddChangeListener(IChangeListener listener)Adds the given change listener to the list of change listeners.voidaddDisposeListener(IDisposeListener listener)Adds the given dispose listener to the list of dispose listeners.voidaddMapChangeListener(IMapChangeListener<? super K,? super V> listener)voidaddStaleListener(IStaleListener listener)Adds the given stale listener to the list of stale listeners.protected voidcheckRealm()Asserts that the realm is the current realm.voiddispose()Disposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.protected voidfireChange()Fires change events.protected voidfireMapChange(MapDiff<K,V> diff)Fires map change events.protected voidfireStale()Fires stale events.protected voidfirstListenerAdded()ObjectgetKeyType()Returns the element type for thekeysetof this observable map, ornullif the keyset is untyped.RealmgetRealm()Returns the realm for this observable.ObjectgetValueType()Returns the element type for thevaluesof this observable map, ornullif the values collection is untyped.protected booleanhasListeners()booleanisDisposed()Returns whether the observable has been disposedbooleanisStale()Returns whether the state of this observable is stale and is expected to change soon.protected voidlastListenerRemoved()voidremoveChangeListener(IChangeListener listener)Removes the given change listener from the list of change listeners.voidremoveDisposeListener(IDisposeListener listener)Removes the given dispose listener from the list of dispose listeners.voidremoveMapChangeListener(IMapChangeListener<? super K,? super V> listener)voidremoveStaleListener(IStaleListener listener)Removes the given stale listener from the list of stale listeners.voidsetStale(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-
-
-
Method Detail
-
lastListenerRemoved
protected void lastListenerRemoved()
-
firstListenerAdded
protected void firstListenerAdded()
-
addMapChangeListener
public void addMapChangeListener(IMapChangeListener<? super K,? super V> listener)
- Specified by:
addMapChangeListenerin interfaceIObservableMap<K,V>
-
removeMapChangeListener
public void removeMapChangeListener(IMapChangeListener<? super K,? super V> listener)
- Specified by:
removeMapChangeListenerin interfaceIObservableMap<K,V>
-
addChangeListener
public void addChangeListener(IChangeListener listener)
Description copied from interface:IObservableAdds 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:
addChangeListenerin interfaceIObservable
-
addStaleListener
public void addStaleListener(IStaleListener listener)
Description copied from interface:IObservableAdds 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:
addStaleListenerin interfaceIObservable- 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:IObservableAdds the given dispose listener to the list of dispose listeners. Dispose listeners are notified when an observable has been disposed.- Specified by:
addDisposeListenerin interfaceIObservable- Parameters:
listener- the listener to add- Since:
- 1.2
-
removeDisposeListener
public void removeDisposeListener(IDisposeListener listener)
Description copied from interface:IObservableRemoves 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:
removeDisposeListenerin interfaceIObservable- Parameters:
listener- the listener to remove- Since:
- 1.2
-
isDisposed
public boolean isDisposed()
Description copied from interface:IObservableReturns whether the observable has been disposed- Specified by:
isDisposedin interfaceIObservable- Returns:
- whether the observable has been disposed
- Since:
- 1.2
-
dispose
public void dispose()
Description copied from interface:IObservableDisposes of this observable object, removing all listeners registered with this object, and all listeners this object might have registered on other objects.- Specified by:
disposein interfaceIObservable
-
getRealm
public Realm getRealm()
Description copied from interface:IObservableReturns 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:
getRealmin interfaceIObservable- Returns:
- the realm
-
isStale
public boolean isStale()
Description copied from interface:IObservableReturns 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:
isStalein interfaceIObservable- Returns:
- true if this observable's state is stale and will change soon.
-
getKeyType
public Object getKeyType()
Description copied from interface:IObservableMapReturns the element type for thekeysetof this observable map, ornullif the keyset is untyped.- Specified by:
getKeyTypein interfaceIObservableMap<K,V>- Returns:
- the element type for the
keysetof this observable map, ornullif the keyset is untyped. - Since:
- 1.2
-
getValueType
public Object getValueType()
Description copied from interface:IObservableMapReturns the element type for thevaluesof this observable map, ornullif the values collection is untyped.- Specified by:
getValueTypein interfaceIObservableMap<K,V>- Returns:
- the element type for the
valuesof this observable map, ornullif the values collection is untyped. - Since:
- 1.2
-
removeChangeListener
public void removeChangeListener(IChangeListener listener)
Description copied from interface:IObservableRemoves 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:
removeChangeListenerin interfaceIObservable
-
removeStaleListener
public void removeStaleListener(IStaleListener listener)
Description copied from interface:IObservableRemoves 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:
removeStaleListenerin interfaceIObservable
-
setStale
public void setStale(boolean stale)
Sets the stale state. Must be invoked from the current realm.- Parameters:
stale-
-
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-
-
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()
-
-