Package io.github.mmm.value.observable
Class AbstractObservableValue<V>
- java.lang.Object
-
- io.github.mmm.event.AbstractEventSource<ObservableEvent<V>,ObservableEventListener<? super V>>
-
- io.github.mmm.value.observable.AbstractObservableValue<V>
-
- Type Parameters:
V
- type of the observablevalue
.
- All Implemented Interfaces:
EventSource<ObservableEvent<V>,ObservableEventListener<? super V>>
,ObservableValue<V>
,ReadableValue<V>
,Supplier<V>
- Direct Known Subclasses:
AbstractWritableObservableValue
,Binding
public abstract class AbstractObservableValue<V> extends AbstractEventSource<ObservableEvent<V>,ObservableEventListener<? super V>> implements ObservableValue<V>
Abstract base implementation ofObservableValue
that handlesObservableEventListener
s.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description AbstractObservableValue()
The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ObservableEventListener<? super V> listener, boolean weak)
Adds anEventListener
which will be notified whenever the an event occurs (something changes).protected void
fireChange(Object change)
Fires a defaultvalue change
event.protected void
fireEvent()
Fires a default value change event.protected void
fireEvent(ObservableEvent<V> event)
protected void
fireEventFor(AbstractObservableValue<?> observable)
protected <T> void
fireEventFor(AbstractObservableValue<T> observable, ObservableEvent<T> event)
protected void
fireEventWithOldValue(V oldValue)
Fires a default value change event if theold value
is known (currently available anyhow).protected boolean
hasChangeAwareListeners()
protected void
invalidate()
Invalidates this observable in case it's value is computed.boolean
removeListener(ObservableEventListener<? super V> listener)
This method removes anEventListener
.String
toString()
void
toString(StringBuilder sb)
-
Methods inherited from class io.github.mmm.event.AbstractEventSource
getEventAdapter, hasListeners
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.github.mmm.event.EventSource
addListener, addWeakListener
-
Methods inherited from interface io.github.mmm.value.ReadableValue
get, getSafe
-
-
-
-
Method Detail
-
addListener
public void addListener(ObservableEventListener<? super V> 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<ObservableEvent<V>,ObservableEventListener<? super V>>
- Overrides:
addListener
in classAbstractEventSource<ObservableEvent<V>,ObservableEventListener<? super V>>
- 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(ObservableEventListener<? super V> 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<ObservableEvent<V>,ObservableEventListener<? super V>>
- Overrides:
removeListener
in classAbstractEventSource<ObservableEvent<V>,ObservableEventListener<? super V>>
- Parameters:
listener
- is theEventListener
to unregister.- Returns:
true
if the givenlistener
has successfully been removed,false
if thelistener
was NOTregistered
.
-
hasChangeAwareListeners
protected boolean hasChangeAwareListeners()
- Returns:
true
if at least oneChangeAwareObservableEventListener
isregistered
,false
otherwise (to avoid building andsending
change
s for better performance).
-
fireEvent
protected void fireEvent()
Fires a default value change event.- See Also:
fireEvent(ObservableEvent)
-
fireEventWithOldValue
protected void fireEventWithOldValue(V oldValue)
Fires a default value change event if theold value
is known (currently available anyhow).- Parameters:
oldValue
- theold value
. May benull
.- See Also:
fireEvent(ObservableEvent)
-
fireChange
protected void fireChange(Object change)
Fires a defaultvalue change
event.- Parameters:
change
- thechange
.- See Also:
fireEvent(ObservableEvent)
-
fireEvent
protected void fireEvent(ObservableEvent<V> event)
- Overrides:
fireEvent
in classAbstractEventSource<ObservableEvent<V>,ObservableEventListener<? super V>>
- Parameters:
event
- the event tosend
to allregistered
EventListener
s.
-
fireEventFor
protected <T> void fireEventFor(AbstractObservableValue<T> observable, ObservableEvent<T> event)
- Type Parameters:
T
- type of the observable value.- Parameters:
observable
- theAbstractObservableValue
where to invokefireEvent(ObservableEvent)
(if prevented due to visibility issues).event
- theObservableEvent
to send.
-
fireEventFor
protected void fireEventFor(AbstractObservableValue<?> observable)
- Parameters:
observable
- theAbstractObservableValue
where to invokefireEvent()
(if prevented due to visibility issues).
-
invalidate
protected void invalidate()
Invalidates this observable in case it's value is computed.
-
toString
public void toString(StringBuilder sb)
- Specified by:
toString
in interfaceObservableValue<V>
- Parameters:
sb
- theStringBuilder
where to append the details of this property fortoString()
-Representation.
-
-