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>
- Direct Known Subclasses:
Property
public abstract class AbstractWritableObservableValue<V> extends AbstractObservableValue<V> implements WritableObservableValue<V>
Abstract base implementation ofWritableObservableValue
that handles bindings.- Since:
- 1.0.0
-
-
Constructor Summary
Constructors Constructor Description AbstractWritableObservableValue()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected 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
doSet(V newValue)
V
get()
boolean
isBoundOneWay()
protected boolean
isValueEqual(V newValue, V oldValue)
Null-safe check if twovalues
are considered equal (unchanged).protected void
requireWritable()
void
set(V value)
protected void
setWithChange(V oldValue, V value)
Internal method called fromset(Object)
if the value actually changed.void
unbindOneWay()
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
-
-
-
-
Method Detail
-
get
public V get()
-
bindOneWay
public void bindOneWay(ObservableValue<? extends V> observable)
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:
WritableObservableValue.unbindOneWay()
,WritableObservableValue.isBoundOneWay()
-
bindInternal
protected void bindInternal(ObservableValue<? extends V> observable)
Internal method ofbindOneWay(ObservableValue)
. Do not call.- Parameters:
observable
- theObservableValue
to bind.- See Also:
bindOneWay(ObservableValue)
-
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:
WritableObservableValue.bindOneWay(ObservableValue)
-
isBoundOneWay
public boolean isBoundOneWay()
- Specified by:
isBoundOneWay
in interfaceWritableObservableValue<V>
- Returns:
true
if this object isbound
,false
otherwise.- See Also:
WritableObservableValue.bindOneWay(ObservableValue)
-
bindTwoWay
public void bindTwoWay(WritableObservableValue<V> other)
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:
WritableObservableValue.unbindTwoWay(WritableObservableValue)
-
unbindTwoWay
public void unbindTwoWay(WritableObservableValue<V> other)
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:
WritableObservableValue.bindTwoWay(WritableObservableValue)
-
set
public void set(V value)
- Specified by:
set
in interfaceWritableValue<V>
- Parameters:
value
- the newvalue
.
-
isValueEqual
protected boolean isValueEqual(V newValue, V oldValue)
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
protected void setWithChange(V oldValue, V value)
Internal method called fromset(Object)
if the value actually changed.- Parameters:
oldValue
- the old value.value
- the new value.
-
requireWritable
protected void requireWritable() throws IllegalStateException
- Throws:
IllegalStateException
- if this property is not writable.
-
doSet
protected abstract void doSet(V newValue)
- Parameters:
newValue
- the newvalue
to set.- See Also:
set(Object)
-
-