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>
- All Implemented Interfaces:
Destructible
- 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 TypeMethodDescriptionaddObserver(Observer<T> observer) voiddestroy()Removes all observers.protected Loggerprotected voidonValueChange(T oldValue, T newValue) Triggers all observers with the newValue whenever the value changes.voidAdds an observer that is immediately called with the current value.voidremoveObserver(Observer<T> observer) voidSets the logger of this property, which is used to log errors thrown by observers.Methods inherited from class dev.prozilla.pine.common.property.MutableProperty
getValue, setValueMethods inherited from class dev.prozilla.pine.common.property.VariableProperty
exists, hasValue
-
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
Triggers all observers with the newValue whenever the value changes.- Overrides:
onValueChangein classMutableProperty<T>- Parameters:
oldValue- The previous valuenewValue- The new value
-
getLogger
-
destroy
public void destroy()Removes all observers.- Specified by:
destroyin interfaceDestructible
-