Interface Observable<T>

Type Parameters:
T - element type
All Known Subinterfaces:
CollectionObservable<E,C>, ListObservable<E>, MutableObservable<T>, SetObservable<E>
All Known Implementing Classes:
ObservableCompound

@AvailableSince("0.0.39") public interface Observable<T>
Represents a mutable state with listeners
See Also:
  • Method Details

    • empty

      static <T> Observable<T> empty()
      Return immutable observer with null value
      Type Parameters:
      T - element type Identity is guaranteed across calls to this method.
      Returns:
      Empty observer
    • immutable

      static <T> Observable<T> immutable(T value)
      Creates an immutable observable encompassing given value
      Type Parameters:
      T - element type
      Parameters:
      value - value
      Returns:
      new observable instance
    • mutable

      static <T> MutableObservable<T> mutable(T value)
      Creates a mutable observable encompassing given value
      Type Parameters:
      T - element type
      Parameters:
      value - value
      Returns:
      new observable instance
    • list

      static <E> ListObservable<E> list()
      Creates a new ListObservable with an empty list, it would use ArrayList as its list implementation
    • list

      static <E> ListObservable<E> list(List<E> list)
      Creates a new ListObservable with the given list
      Parameters:
      list - should be modifiable
    • set

      static <E> SetObservable<E> set()
      Create a new SetObservable with an empty set, using HashSet as is set implementation
    • set

      static <E> SetObservable<E> set(Set<E> set)
      Create a new SetObservable with the given set
      Parameters:
      set - should be modifiable
    • compound

      static <T> Observable<T> compound(Function<List<?>,T> function, List<Observable<?>> depends)
      Creates a new compound observable with the given function and list of dependents
      Type Parameters:
      T - the type of the final value
      Parameters:
      function - the function that will be used to compute the final value
      depends - encapsulated observables that will be used as arguments for the function
      Returns:
      a new observable instance
    • compound

      static <ARG0> Observable<CompoundRecords.RecordOf1<ARG0>> compound(Observable<ARG0> arg0)
      Creates a ObservableCompound with a single argument.
      Type Parameters:
      ARG0 - The type of the first argument.
      Parameters:
      arg0 - The state that provides the first argument.
      Returns:
      A state representing a record with a single arguments.
    • compound

      static <ARG0, ARG1> Observable<CompoundRecords.RecordOf2<ARG0,ARG1>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1)
      Creates a ObservableCompound with two arguments.
      Type Parameters:
      ARG0 - The type of the 1st argument.
      ARG1 - The type of the 2nd argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the second argument.
      Returns:
      A state representing a record with two arguments.
    • compound

      static <ARG0, ARG1, ARG2> Observable<CompoundRecords.RecordOf3<ARG0,ARG1,ARG2>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2)
      Create a ObservableCompound with three arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      Returns:
      A state representing a record with three arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3> Observable<CompoundRecords.RecordOf4<ARG0,ARG1,ARG2,ARG3>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3)
      Create a ObservableCompound with four arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      Returns:
      A state representing a record with four arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3, ARG4> Observable<CompoundRecords.RecordOf5<ARG0,ARG1,ARG2,ARG3,ARG4>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3, Observable<ARG4> arg4)
      Create a ObservableCompound with five arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      ARG4 - The type of the 5th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      arg4 - The state that provides the 5th argument.
      Returns:
      A state representing a record with five arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3, ARG4, ARG5> Observable<CompoundRecords.RecordOf6<ARG0,ARG1,ARG2,ARG3,ARG4,ARG5>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3, Observable<ARG4> arg4, Observable<ARG5> arg5)
      Create a ObservableCompound with six arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      ARG4 - The type of the 5th argument.
      ARG5 - The type of the 6th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      arg4 - The state that provides the 5th argument.
      arg5 - The state that provides the 6th argument.
      Returns:
      A state representing a record with six arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6> Observable<CompoundRecords.RecordOf7<ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3, Observable<ARG4> arg4, Observable<ARG5> arg5, Observable<ARG6> arg6)
      Create a ObservableCompound with seven arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      ARG4 - The type of the 5th argument.
      ARG5 - The type of the 6th argument.
      ARG6 - The type of the 7th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      arg4 - The state that provides the 5th argument.
      arg5 - The state that provides the 6th argument.
      arg6 - The state that provides the 7th argument.
      Returns:
      A state representing a record with seven arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7> Observable<CompoundRecords.RecordOf8<ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3, Observable<ARG4> arg4, Observable<ARG5> arg5, Observable<ARG6> arg6, Observable<ARG7> arg7)
      Create a ObservableCompound with eight arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      ARG4 - The type of the 5th argument.
      ARG5 - The type of the 6th argument.
      ARG6 - The type of the 7th argument.
      ARG7 - The type of the 8th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      arg4 - The state that provides the 5th argument.
      arg5 - The state that provides the 6th argument.
      arg6 - The state that provides the 7th argument.
      arg7 - The state that provides the 8th argument.
      Returns:
      A state representing a record with eight arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8> Observable<CompoundRecords.RecordOf9<ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3, Observable<ARG4> arg4, Observable<ARG5> arg5, Observable<ARG6> arg6, Observable<ARG7> arg7, Observable<ARG8> arg8)
      Create a ObservableCompound with nine arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      ARG4 - The type of the 5th argument.
      ARG5 - The type of the 6th argument.
      ARG6 - The type of the 7th argument.
      ARG7 - The type of the 8th argument.
      ARG8 - The type of the 9th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      arg4 - The state that provides the 5th argument.
      arg5 - The state that provides the 6th argument.
      arg6 - The state that provides the 7th argument.
      arg7 - The state that provides the 8th argument.
      arg8 - The state that provides the 9th argument.
      Returns:
      A state representing a record with nine arguments.
    • compound

      static <ARG0, ARG1, ARG2, ARG3, ARG4, ARG5, ARG6, ARG7, ARG8, ARG9> Observable<CompoundRecords.RecordOf10<ARG0,ARG1,ARG2,ARG3,ARG4,ARG5,ARG6,ARG7,ARG8,ARG9>> compound(Observable<ARG0> arg0, Observable<ARG1> arg1, Observable<ARG2> arg2, Observable<ARG3> arg3, Observable<ARG4> arg4, Observable<ARG5> arg5, Observable<ARG6> arg6, Observable<ARG7> arg7, Observable<ARG8> arg8, Observable<ARG9> arg9)
      Create a ObservableCompound with ten arguments.
      Type Parameters:
      ARG0 - The type of the first argument.
      ARG1 - The type of the 2nd argument.
      ARG2 - The type of the 3rd argument.
      ARG3 - The type of the 4th argument.
      ARG4 - The type of the 5th argument.
      ARG5 - The type of the 6th argument.
      ARG6 - The type of the 7th argument.
      ARG7 - The type of the 8th argument.
      ARG8 - The type of the 9th argument.
      ARG9 - The type of the 10th argument.
      Parameters:
      arg0 - The state that provides the first argument.
      arg1 - The state that provides the 2nd argument.
      arg2 - The state that provides the 3rd argument.
      arg3 - The state that provides the 4th argument.
      arg4 - The state that provides the 5th argument.
      arg5 - The state that provides the 6th argument.
      arg6 - The state that provides the 7th argument.
      arg7 - The state that provides the 8th argument.
      arg8 - The state that provides the 9th argument.
      arg9 - The state that provides the 10th argument.
      Returns:
      A state representing a record with ten arguments.
    • get

      T get()
      Will return the value of the state if it is dirty it will recompute it
      Returns:
      value of state after recomputing if dirty otherwise the current value
    • observe

      void observe(Observer observer)
      Adds an observer to the state
      Parameters:
      observer - the observer we want to add
      See Also:
    • removeObserver

      boolean removeObserver(Observer observer)
      Removes an observer from the state
      Parameters:
      observer - observer we want to remove
      Returns:
      true if the observer was listening, false otherwise
      See Also:
    • map

      default <M> Observable<M> map(Function<T,M> mapper)
      Maps the value of the observable using the given function when it is dirty
      Type Parameters:
      M - The return type
      Parameters:
      mapper - the mapper function that will be used to map the value
      Returns:
      new Instance of mapped observable
    • watch

      default AttachedWatcher<T> watch(WatcherManager watcherManager, Consumer<T> consumer)
      Create a watcher for the observable that will be attached to the given watcher manager and run the given action
      Parameters:
      watcherManager - operator to attach to
      consumer - action to run
      Returns:
      a new attached watcher