Class Observable<T>

java.lang.Object
com.luciad.utils.Observable<T>
Type Parameters:
T - the type to hold

public class Observable<T> extends Object
This class makes it possible to hold and observe a value that can change over time.
  • Constructor Details

    • Observable

      public Observable(T initialValue)
      Constructs the observable with an initial value.
      Parameters:
      initialValue - the initial value.
    • Observable

      public Observable(T initialValue, @NotNull Class<T> clazz)
      Constructs the observable with an initial value.
      Parameters:
      initialValue - the initial value.
      clazz - the class of initialValue.
  • Method Details

    • create

      @NotNull public static <T> Observable<T> create(T initialValue)
      Creates a new Observable with the given initial value.
      Parameters:
      initialValue - the initial value.
      Returns:
      the created Observable.
    • create

      @NotNull public static <U> Observable<U> create(U initialValue, @NotNull Class<U> clazz)
      Creates a new Observable with the given initial value
      Type Parameters:
      U - the type of the initial value.
      Parameters:
      initialValue - the initial value.
      clazz - the class of hte initial value.
      Returns:
      the created Observable.
    • getValue

      public T getValue()
      Returns the observable value.
      Returns:
      the observable value.
    • setValue

      public void setValue(T value) throws IllegalStateException
      Sets the observable value.

      This triggers a call to the configured callbacks.

      Parameters:
      value - the new value
      Throws:
      IllegalStateException - when calling setValue on derived instances for example.
    • addCallback

      public void addCallback(@NotNull IInvalidationCallback callback) throws IllegalArgumentException
      Adds a callback that is notified when setValue is called.
      Parameters:
      callback - a callback
      Throws:
      IllegalArgumentException - when the call back is already added.
    • removeCallback

      public void removeCallback(@NotNull IInvalidationCallback callback) throws IllegalArgumentException
      Remove the given callback.
      Parameters:
      callback - a callback
      Throws:
      IllegalArgumentException - when the call back is not known.