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 void
addListener(L listener, boolean weak)
Adds anEventListener
which will be notified whenever the an event occurs (something changes).protected void
fireEvent(E event)
protected EventSourceAdapter<E,L>
getEventAdapter()
protected boolean
hasListeners()
boolean
removeListener(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:EventSource
Adds anEventListener
which 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 sameEventListener
instance may be registered for differentEventSource
s.- Specified by:
addListener
in interfaceEventSource<E,L extends EventListener<?>>
- Parameters:
listener
- theEventListener
to register.weak
- -true
if theEventListener
may be garbage collected without beingremoved
via aWeakReference
,false
otherwise (if the listener will be associated using a strong reference). When providingtrue
here (useWeakReference
), you need to store a reference to your registeredEventListener
yourself 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:EventSource
This method removes anEventListener
. If theEventListener
was not registered before this method does not do any change. Otherwise the first matchingEventListener
will be removed. So if youadded
anEventListener
multiple times, only the first occurrence will be removed.
For performance reasonsEventListener.isMatchedUsingEquals()
returnsfalse
by default. To force the usage ofequals
instead, ensure yourEventListener
implementation overridesObject.equals(Object)
andEventListener.isMatchedUsingEquals()
returningtrue
.- Specified by:
removeListener
in interfaceEventSource<E,L extends EventListener<?>>
- Parameters:
listener
- is theEventListener
to unregister.- Returns:
true
if the givenlistener
has successfully been removed,false
if thelistener
was NOTregistered
.
-
hasListeners
protected boolean hasListeners()
- Returns:
true
if at least oneEventListener
isregistered
,false
otherwise.
-
getEventAdapter
protected EventSourceAdapter<E,L> getEventAdapter()
- Returns:
- the
EventSourceAdapter
.
-
fireEvent
protected void fireEvent(E event)
- Parameters:
event
- the event tosend
to allregistered
EventListener
s.
-
-