Module io.github.mmm.event
Package io.github.mmm.event
Class AbstractEventSource<E,L extends EventListener<?>>
- java.lang.Object
-
- io.github.mmm.event.AbstractEventSource<E,L>
-
- All Implemented Interfaces:
EventSource<E,L>
- Direct Known Subclasses:
AbstractObservableValue,AbstractUiNavigationManager
public abstract class AbstractEventSource<E,L extends EventListener<?>> extends Object implements EventSource<E,L>
Implementation ofEventSource.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description AbstractEventSource()The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddListener(L listener, boolean weak)Adds anEventListenerwhich will be notified whenever the an event occurs (something changes).protected voidfireEvent(E event)protected EventSourceAdapter<E,L>getEventAdapter()protected booleanhasListeners()booleanremoveListener(L listener)This method removes anEventListener.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface io.github.mmm.event.EventSource
addListener, addWeakListener
-
-
-
-
Method Detail
-
addListener
public void addListener(L listener, boolean weak)
Description copied from interface:EventSourceAdds anEventListenerwhich will be notified whenever the an event occurs (something changes). If the same listener is added more than once, it will be notified more than once. The sameEventListenerinstance may be registered for differentEventSources.- Specified by:
addListenerin interfaceEventSource<E,L extends EventListener<?>>- Parameters:
listener- theEventListenerto register.weak- -trueif theEventListenermay be garbage collected without beingremovedvia aWeakReference,falseotherwise (if the listener will be associated using a strong reference). When providingtruehere (useWeakReference), you need to store a reference to your registeredEventListeneryourself in the owning parent object so it is not garbage-collected too early.- See Also:
EventSource.addWeakListener(EventListener)
-
removeListener
public boolean removeListener(L listener)
Description copied from interface:EventSourceThis method removes anEventListener. If theEventListenerwas not registered before this method does not do any change. Otherwise the first matchingEventListenerwill be removed. So if youaddedanEventListenermultiple times, only the first occurrence will be removed.
For performance reasonsEventListener.isMatchedUsingEquals()returnsfalseby default. To force the usage ofequalsinstead, ensure yourEventListenerimplementation overridesObject.equals(Object)andEventListener.isMatchedUsingEquals()returningtrue.- Specified by:
removeListenerin interfaceEventSource<E,L extends EventListener<?>>- Parameters:
listener- is theEventListenerto unregister.- Returns:
trueif the givenlistenerhas successfully been removed,falseif thelistenerwas NOTregistered.
-
hasListeners
protected boolean hasListeners()
- Returns:
trueif at least oneEventListenerisregistered,falseotherwise.
-
getEventAdapter
protected EventSourceAdapter<E,L> getEventAdapter()
- Returns:
- the
EventSourceAdapter.
-
fireEvent
protected void fireEvent(E event)
- Parameters:
event- the event tosendto allregisteredEventListeners.
-
-