Class WritableValue<T>

Type Parameters:
T - the type of value being observed
All Implemented Interfaces:
IObservable, IObservableValue<T>

public class WritableValue<T> extends AbstractObservableValue<T>
Mutable (writable) implementation of IObservableValue that will maintain a value and fire change events when the value changes.

This class is thread safe. All state accessing methods must be invoked from the current realm. Methods for adding and removing listeners may be invoked from any thread.

Since:
1.0
  • Constructor Details

    • WritableValue

      public WritableValue()
      Constructs a new instance with the default realm, a null value type, and a null value.
    • WritableValue

      public WritableValue(T initialValue, Object valueType)
      Constructs a new instance with the default realm.
      Parameters:
      initialValue - can be null
      valueType - can be null
    • WritableValue

      public WritableValue(Realm realm)
      Constructs a new instance with the provided realm, a null value type, and a null initial value.
      Parameters:
      realm - the realm
    • WritableValue

      public WritableValue(Realm realm, T initialValue, Object valueType)
      Constructs a new instance.
      Parameters:
      realm - the realm
      initialValue - can be null
      valueType - can be null
  • Method Details

    • doGetValue

      public T doGetValue()
      Specified by:
      doGetValue in class AbstractObservableValue<T>
    • doSetValue

      public void doSetValue(T value)
      Description copied from class: AbstractObservableValue
      Template method for setting the value of the observable. By default the method throws an UnsupportedOperationException.
      Overrides:
      doSetValue in class AbstractObservableValue<T>
      Parameters:
      value - The value to set.
    • getValueType

      public Object getValueType()
      Description copied from interface: IObservableValue
      The value type of this observable value, or null if this observable value is untyped.
      Returns:
      the value type, or null
    • withValueType

      public static <T2> WritableValue<T2> withValueType(Object elementType)
      Type Parameters:
      T2 - the type of observed value of the created instance
      Parameters:
      elementType - can be null
      Returns:
      new instance with the default realm and a value of null
    • addListener

      protected void addListener(Object listenerType, IObservablesListener listener)
      Parameters:
      listenerType - arbitrary object to identify a type of the listener
      listener - the listener to add; not null
    • removeListener

      protected void removeListener(Object listenerType, IObservablesListener listener)
      Parameters:
      listenerType - arbitrary object to identify a type of the listener
      listener - the listener to remove; not null
    • hasListeners

      protected boolean hasListeners()
    • fireEvent

      protected void fireEvent(ObservableEvent event)
    • firstListenerAdded

      protected void firstListenerAdded()
    • lastListenerRemoved

      protected void lastListenerRemoved()
    • getRealm

      public Realm getRealm()
      Returns:
      Returns the realm.
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException