Package io.github.mmm.value.observable
Class AbstractWritableObservableValue<V>
java.lang.Object
io.github.mmm.event.AbstractEventSource<ObservableEvent<V>,ObservableEventListener<? super V>>
io.github.mmm.value.observable.AbstractObservableValue<V>
io.github.mmm.value.observable.AbstractWritableObservableValue<V>
- Type Parameters:
V
- type of the observablevalue
.
- All Implemented Interfaces:
EventSource<ObservableEvent<V>,
,ObservableEventListener<? super V>> ObservableValue<V>
,WritableObservableValue<V>
,ReadableValue<V>
,WritableValue<V>
,Supplier<V>
public abstract class AbstractWritableObservableValue<V>
extends AbstractObservableValue<V>
implements WritableObservableValue<V>
Abstract base implementation of
WritableObservableValue
that handles bindings.- Since:
- 1.0.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
bindInternal
(ObservableValue<? extends V> observable) Internal method ofbindOneWay(ObservableValue)
.void
bindOneWay
(ObservableValue<? extends V> observable) Creates a unidirection binding for this object.
ATTENTION:
An unidirectional binding is very strict.void
bindTwoWay
(WritableObservableValue<V> other) Create a bidirectional binding between this object and the given one.protected abstract V
doGet()
protected abstract void
get()
boolean
protected boolean
isValueEqual
(V newValue, V oldValue) Null-safe check if twovalues
are considered equal (unchanged).protected void
void
protected void
setWithChange
(V oldValue, V value) Internal method called fromset(Object)
if the value actually changed.void
Removes theunidirectional binding
from this object.void
unbindTwoWay
(WritableObservableValue<V> other) Removes abidirectional binding
between this object and the given one.Methods inherited from class io.github.mmm.value.observable.AbstractObservableValue
addListener, fireChange, fireEvent, fireEvent, fireEventFor, fireEventFor, fireEventWithOldValue, hasChangeAwareListeners, invalidate, removeListener, toString, toString
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, addListener, addWeakListener, removeListener
Methods inherited from interface io.github.mmm.value.observable.ObservableValue
toString
Methods inherited from interface io.github.mmm.value.ReadableValue
getSafe
-
Constructor Details
-
AbstractWritableObservableValue
public AbstractWritableObservableValue()
-
-
Method Details
-
get
-
doGet
- Returns:
- the internal
value
.
-
bindOneWay
Description copied from interface:WritableObservableValue
Creates a unidirection binding for this object.
ATTENTION:
An unidirectional binding is very strict. It makes this object to appear exactly as theObservableValue
it is bound to. After creating the unidirectional binding, calls toWritableValue.set(Object)
will fail. This is very different to anbidirectional binding
.- Specified by:
bindOneWay
in interfaceWritableObservableValue<V>
- Parameters:
observable
- theObservableValue
this object should be bound to.- See Also:
-
bindInternal
Internal method ofbindOneWay(ObservableValue)
. Do not call.- Parameters:
observable
- theObservableValue
to bind.- See Also:
-
unbindOneWay
public void unbindOneWay()Description copied from interface:WritableObservableValue
Removes theunidirectional binding
from this object. If this object is notbound
, this method has no effect.- Specified by:
unbindOneWay
in interfaceWritableObservableValue<V>
- See Also:
-
isBoundOneWay
public boolean isBoundOneWay()- Specified by:
isBoundOneWay
in interfaceWritableObservableValue<V>
- Returns:
true
if this object isbound
,false
otherwise.- See Also:
-
bindTwoWay
Description copied from interface:WritableObservableValue
Create a bidirectional binding between this object and the given one. After a bidirectional binding,WritableValue.set(Object)
on this object will propagate its value to the bound one and vice versa. Bidirectional bindings exists independently ofunidirectional bindings
. However, it is bad practice to combine both. It is possible to have multiple bidirectional bindings for the same object.- Specified by:
bindTwoWay
in interfaceWritableObservableValue<V>
- Parameters:
other
- the otherWritableObservableValue
to bind bidirectional.- See Also:
-
unbindTwoWay
Description copied from interface:WritableObservableValue
Removes abidirectional binding
between this object and the given one. If no bidirectional binding between these objects exists, this method has no effect. It is possible tounbind
in inverse order. So to unbind twobidirectional bound
objects it does not matter if you callunbindBidirectional
on the first with the second as argument or vice versa.- Specified by:
unbindTwoWay
in interfaceWritableObservableValue<V>
- Parameters:
other
- the otherWritableObservableValue
to unbind bidirectional.- See Also:
-
set
- Specified by:
set
in interfaceWritableValue<V>
-
isValueEqual
Null-safe check if twovalues
are considered equal (unchanged).- Parameters:
newValue
- the new value.oldValue
- the old value.- Returns:
true
if equal (unchanged),false
otherwise (changed),
-
setWithChange
Internal method called fromset(Object)
if the value actually changed.- Parameters:
oldValue
- the old value.value
- the new value.
-
requireWritable
- Throws:
IllegalStateException
- if this property is not writable.
-
doSet
- Parameters:
newValue
- the newvalue
to set.- See Also:
-