- Type Parameters:
T
- the value type
- All Superinterfaces:
Observable<T>
,Observer<T>
- All Known Subinterfaces:
EntityEditModel.EditableEntity
,FilterComboBoxModel.ComboBoxItems<T>
,FilterComboBoxModel.NullItem<T>
,FilterModel.Items<T>
,MultiItemSelection.Indexes
,MultiItemSelection.Items<R>
- All Known Implementing Classes:
NullableToggleButtonModel.ToggleState
A wrapper for a mutable value, providing a change observer.
class Person {
private final Event<String> nameChanged = Event.event();
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
nameChanged.accept(name);
}
}
Person person = new Person();
Mutable<String> mutableName = new Mutable<>() {
@Override
public String get() {
return person.getName();
}
@Override
public void set(String value) {
person.setName(value);
}
@Override
public Observer<String> observer() {
return person.nameChanged.observer();
}
};
mutableName.addConsumer(newName ->
System.out.println("Name changed to " + newName));
-
Method Summary
Methods inherited from interface is.codion.common.observer.Observable
addConsumer, addListener, addWeakConsumer, addWeakListener, get, observer, optional, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener
-
Method Details
-
set
Sets the value- Parameters:
value
- the value to set
-
clear
default void clear()Clears thisMutable
instance by setting the value to null
-