Package com.dua3.utility.concurrent
Class SimpleValue<T extends @Nullable Object>
java.lang.Object
com.dua3.utility.concurrent.SimpleValue<T>
- Type Parameters:
T- the type of the value
- All Implemented Interfaces:
ReadOnlyValue<T>,Value<T>
A simple implementation of the Value interface that stores a single value of any type.
-
Constructor Summary
ConstructorsConstructorDescriptionSimpleValue(T initialValue) Initializes a new instance of theSimpleValueclass. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddChangeListener(BiConsumer<? super T, ? super T> listener) Adds a change listener for the given method.booleanget()Retrieves the value of type T.Collection<BiConsumer<? super T, ? super T>> Returns a collection of all the change listeners currently registered for this method.inthashCode()voidremoveChangeListener(BiConsumer<? super T, ? super T> listener) Removes a change listener for the given method.voidSets the value of the method.toString()
-
Constructor Details
-
SimpleValue
Initializes a new instance of theSimpleValueclass.- Parameters:
initialValue- the initial value of theSimpleValue
-
-
Method Details
-
get
Description copied from interface:ReadOnlyValueRetrieves the value of type T.- Specified by:
getin interfaceReadOnlyValue<T extends @Nullable Object>- Returns:
- The value of type T.
-
addChangeListener
Description copied from interface:ReadOnlyValueAdds a change listener for the given method. The change listener will be triggered whenever the value of type T changes.- Specified by:
addChangeListenerin interfaceReadOnlyValue<T extends @Nullable Object>- Parameters:
listener- The change listener to be added. The change listener is a BiConsumer that accepts two parameters: - The previous value of type T - The new value of type T The change listener does not return a value.
-
removeChangeListener
Description copied from interface:ReadOnlyValueRemoves a change listener for the given method. The change listener will no longer be triggered whenever the value of type T changes.- Specified by:
removeChangeListenerin interfaceReadOnlyValue<T extends @Nullable Object>- Parameters:
listener- The change listener to be removed. The change listener is a BiConsumer that was previously added using the addChangeListener method.
-
getChangeListeners
Description copied from interface:ReadOnlyValueReturns a collection of all the change listeners currently registered for this method.- Specified by:
getChangeListenersin interfaceReadOnlyValue<T extends @Nullable Object>- Returns:
- A collection of change listeners, each represented as a BiConsumer. The change listeners are used to listen for changes in the value of type T.
-
set
Description copied from interface:ValueSets the value of the method. -
equals
-
hashCode
public int hashCode() -
toString
-