Interface Observable<T>

  • Type Parameters:
    T - the type of value to observe
    All Known Implementing Classes:
    SimpleObservable, SynchronizedObservable

    public interface Observable<T>
    An observable wraps a value that, when changed, will notify listeners of the change.
    • Method Detail

      • addObserver

        void addObserver​(Observer<? super T> observer)
        Add an observer to this observable. It will be notified of any future changes to the value of this observable. Listeners will be fired in the order in which they were added, and on the thread that updates the observed value. Because of this, listeners should take as little time as possible to run (unless submitting a long-running task to a worker thread).
      • removeObserver

        void removeObserver​(Observer<? super T> observer)
        Removes an observer from this observable. The observer will not be updated with future changes to the value of this observable.
      • get

        T get()
        Gets the current value of this observable.
      • set

        void set​(T value)
        Sets the value of this observable. If it's not equal to the current value, all observers will be notified of the change.
      • of

        static <T> Observable<T> of​(T value)
        Creates an observable initialized to the given value. This observable is not thread-safe; for a thread-safe observable, use synchronizedOf.
        Type Parameters:
        T - the type of value in the observable
        Parameters:
        value - the initial value of the observable
      • synchronizedOf

        static <T> Observable<T> synchronizedOf​(T value)
        Creates a thread-safe observable initialized to the given value.
        Type Parameters:
        T - the type of value in the observable
        Parameters:
        value - the initial value of the observable