- Type Parameters:
T- the value type
- All Superinterfaces:
Observer<T>
- All Known Subinterfaces:
CalendarPanel.CalendarDate,CalendarPanel.CalendarDateTime,CalendarPanel.CalendarZonedDateTime,ComponentValue<C,,T> EntityConditionModel.ConditionValue,EntityEditModel.EditorValue<T>,EntityEditModel.EntityEditor,FilterModel.FilteredItems<T>,FilterModel.IncludedItems<T>,FilterModel.IncludePredicate<T>,FilterTableColumnModel.ColumnSelection.ColumnIndex,FilterTableColumnModel.HiddenColumns<C>,FilterTableColumnModel.VisibleColumns<C>,FilterTableSearchModel.Results,ImagePane.ImageValue,MultiSelection.Indexes,MultiSelection.Items<R>,ObservableValueCollection<T,,C> ObservableValueList<T>,ObservableValueSet<T>,Value<T>,ValueCollection<T,,C> ValueList<T>,ValueSet<T>
- All Known Implementing Classes:
AbstractComponentValue,AbstractTextComponentValue,AbstractValue,PropertyValue
A wrapper for a value, providing a change observer.
Thread Safety: Listener management is thread-safe, value access thread-safety is implementation dependent.
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();
Observable<String> observableName = new Observable<>() {
@Override
public String get() {
return person.getName();
}
@Override
public Observer<String> observer() {
return person.nameChanged.observer();
}
};
observableName.addConsumer(newName ->
System.out.println("Name changed to " + newName));
-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.common.reactive.observer.Observer
Observer.Builder<T,B extends Observer.Builder<T, B>> -
Method Summary
Modifier and TypeMethodDescriptionget()default Tdefault TgetOrThrow(String message) default booleanReturns true if the underlying value is equal to the given one.default booleanReturns true if the underlying value is NOT equal to the given one.default booleanisNull()default booleanIf false then get() is guaranteed to never return null.optional()Methods inherited from interface is.codion.common.reactive.observer.Observer
addConsumer, addListener, addWeakConsumer, addWeakListener, observer, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener, when, when
-
Method Details
-
get
- Returns:
- the value
-
getOrThrow
- Returns:
- the value
- Throws:
NoSuchElementException- if no value is present
-
getOrThrow
- Parameters:
message- the error message to use when throwing- Returns:
- the value
- Throws:
NoSuchElementException- if no value is present
-
optional
- Returns:
- an
Optionalwrapping this value.
-
isNull
default boolean isNull()- Returns:
- true if the underlying value is null.
-
isNullable
default boolean isNullable()If false then get() is guaranteed to never return null.- Returns:
- true if this observable can be null
-
is
Returns true if the underlying value is equal to the given one. Note that null == null.- Parameters:
value- the value- Returns:
- true if the underlying value is equal to the given one
-
isNot
Returns true if the underlying value is NOT equal to the given one. Note that null == null.- Parameters:
value- the value- Returns:
- true if the underlying value is NOT equal to the given one
-