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 theSimpleValue
class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addChangeListener
(BiConsumer<? super T, ? super T> listener) Adds a change listener for the given method.boolean
get()
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.int
hashCode()
void
removeChangeListener
(BiConsumer<? super T, ? super T> listener) Removes a change listener for the given method.void
Sets the value of the method.toString()
-
Constructor Details
-
SimpleValue
Initializes a new instance of theSimpleValue
class.- Parameters:
initialValue
- the initial value of theSimpleValue
-
-
Method Details
-
get
Description copied from interface:ReadOnlyValue
Retrieves the value of type T.- Specified by:
get
in interfaceReadOnlyValue<T extends @Nullable Object>
- Returns:
- The value of type T.
-
addChangeListener
Description copied from interface:ReadOnlyValue
Adds a change listener for the given method. The change listener will be triggered whenever the value of type T changes.- Specified by:
addChangeListener
in 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:ReadOnlyValue
Removes a change listener for the given method. The change listener will no longer be triggered whenever the value of type T changes.- Specified by:
removeChangeListener
in 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:ReadOnlyValue
Returns a collection of all the change listeners currently registered for this method.- Specified by:
getChangeListeners
in 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:Value
Sets the value of the method. -
equals
-
hashCode
public int hashCode() -
toString
-