Class ObservableProperty<T>
java.lang.Object
dev.prozilla.pine.common.property.VariableProperty<T>
dev.prozilla.pine.common.property.MutableProperty<T>
dev.prozilla.pine.common.property.observable.ObservableProperty<T>
- Direct Known Subclasses:
ConfigOption
,SelectionProperty
A property that triggers observers whenever its value changes.
-
Field Summary
FieldsFields inherited from class dev.prozilla.pine.common.property.VariableProperty
random
-
Constructor Summary
ConstructorsConstructorDescriptionCreates an observable property without an initial value.ObservableProperty
(T initialValue) Creates an observable property with an initial value. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(Observer<T> observer) protected void
onValueChange
(T oldValue, T newValue) This method is called whenever the value of this property changes.void
Adds an observer that is immediately called with the current value.void
removeObserver
(Observer<T> observer) void
Sets the logger of this property, which is used to log errors thrown by observers.Methods inherited from class dev.prozilla.pine.common.property.MutableProperty
exists, getValue, setValue
-
Field Details
-
logger
-
-
Constructor Details
-
ObservableProperty
public ObservableProperty()Creates an observable property without an initial value. -
ObservableProperty
Creates an observable property with an initial value.- Parameters:
initialValue
- The initial value
-
-
Method Details
-
read
Adds an observer that is immediately called with the current value.This is the equivalent of calling
MutableProperty.getValue()
, then doing something with that value, and then adding an observer which does the same thing each time the value changes.- Parameters:
reader
- The observer
-
addObserver
-
removeObserver
-
setLogger
Sets the logger of this property, which is used to log errors thrown by observers. -
onValueChange
Description copied from class:MutableProperty
This method is called whenever the value of this property changes.The default implementation does nothing.
- Overrides:
onValueChange
in classMutableProperty<T>
- Parameters:
oldValue
- The previous valuenewValue
- The new value
-