Class ObjectProperty<T>
java.lang.Object
com.iohao.net.common.kit.beans.property.ObjectProperty<T>
- All Implemented Interfaces:
PropertyValueObservable<T>
object - Property has listening feature. A listening event will be triggered when the value changes.
YourUser user = new YourUser();
var property = new ObjectProperty(user);
// add listener monitor property object
property.addListener((observable, oldValue, newValue) -> {
log.info("oldValue:{}, newValue:{}", oldValue, newValue);
});
property.set(user); // does not trigger listeners
YourUser user2 = new YourUser();
property.set(user2); // When the value changes,listeners are triggered
property.get(); // value is user2
- Author:
- 渔民小镇
- date:
- 2024-04-17
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(PropertyChangeListener<? super T> listener) Register a change listener to be notified when the value changes.get()get current valuegetValue()Get the current property value.protected voidMark the property as invalid and fire change events to all registered listeners.voidremoveListener(PropertyChangeListener<? super T> listener) Remove a previously registered change listener.voidset current valuevoidSet the property value, triggering listeners if the value changed.toString()
-
Field Details
-
valid
protected boolean valid
-
-
Constructor Details
-
ObjectProperty
public ObjectProperty() -
ObjectProperty
-
-
Method Details
-
getValue
Description copied from interface:PropertyValueObservableGet the current property value.- Returns:
- the current value
-
setValue
Description copied from interface:PropertyValueObservableSet the property value, triggering listeners if the value changed.- Parameters:
value- the new value to set
-
get
-
set
-
toString
-
addListener
Description copied from interface:PropertyValueObservableRegister a change listener to be notified when the value changes.- Specified by:
addListenerin interfacePropertyValueObservable<T>- Parameters:
listener- the listener to register
-
removeListener
Description copied from interface:PropertyValueObservableRemove a previously registered change listener.- Specified by:
removeListenerin interfacePropertyValueObservable<T>- Parameters:
listener- the listener to remove
-
markInvalid
protected void markInvalid()Mark the property as invalid and fire change events to all registered listeners.
-