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>

public class SimpleValue<T extends @Nullable Object> extends Object implements Value<T>
A simple implementation of the Value interface that stores a single value of any type.
  • Constructor Details

    • SimpleValue

      public SimpleValue(T initialValue)
      Initializes a new instance of the SimpleValue class.
      Parameters:
      initialValue - the initial value of the SimpleValue
  • Method Details

    • get

      public T get()
      Description copied from interface: ReadOnlyValue
      Retrieves the value of type T.
      Specified by:
      get in interface ReadOnlyValue<T extends @Nullable Object>
      Returns:
      The value of type T.
    • addChangeListener

      public void addChangeListener(BiConsumer<? super T,? super T> listener)
      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 interface ReadOnlyValue<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

      public void removeChangeListener(BiConsumer<? super T,? super T> listener)
      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 interface ReadOnlyValue<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

      public Collection<BiConsumer<? super T,? super T>> getChangeListeners()
      Description copied from interface: ReadOnlyValue
      Returns a collection of all the change listeners currently registered for this method.
      Specified by:
      getChangeListeners in interface ReadOnlyValue<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

      public void set(T v)
      Description copied from interface: Value
      Sets the value of the method.
      Specified by:
      set in interface Value<T extends @Nullable Object>
      Parameters:
      v - the value to be set
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object