Interface Observable<T>

Type Parameters:
T - the value type
All Superinterfaces:
Observer<T>
All Known Subinterfaces:
CalendarPanel.CalendarDate, CalendarPanel.CalendarDateTime, ComponentValue<T,C>, EntityEditModel.EntityEditor, EntityEditModel.EntityEditor.Exists, EntityEditModel.EntityEditor.Modified, EntityEditModel.ValueEditor<T>, EntityQueryModel.AdditionalCondition, FilterModel.FilteredItems<T>, FilterModel.VisibleItems<T>, FilterTableColumnModel.HiddenColumns<C>, FilterTableColumnModel.VisibleColumns<C>, FilterTableSearchModel.Results, MultiSelection.Index, MultiSelection.Indexes, MultiSelection.Items<R>, ObservableState, ObservableValueList<T>, ObservableValues<T,C>, ObservableValueSet<T>, PropertyValue<T>, SingleSelection.Item<T>, State, State.Combination, Value<T>, ValueList<T>, Values<T,C>, ValueSet<T>
All Known Implementing Classes:
AbstractComponentValue, AbstractTextComponentValue, AbstractValue, NullableToggleButtonModel.ToggleState

public interface Observable<T> extends Observer<T>
A wrapper for a value, providing a change observer.
 
   class Person {
       private final Event<String> nameChanged = Event.event();

       private String name;

       public String getName() {
           return name;
       }

       public void setName(String name) {
           this.name = name;
           nameChanged.accept(name);
      }
   }

   Person person = new Person();

   Observable<String> observableName = new Observable<>() {
       @Override
       public String get() {
           return person.getName();
       }

       @Override
       public Observer<String> observer() {
           return person.nameChanged.observer();
       }
  };

  observableName.addConsumer(newName ->
          System.out.println("Name changed to " + newName));
 
 
  • Method Details

    • get

      @Nullable T get()
      Returns:
      the value
    • getOrThrow

      default T getOrThrow()
      Returns:
      the value
      Throws:
      NoSuchElementException - if no value is present
    • getOrThrow

      default T getOrThrow(String message)
      Parameters:
      message - the error message to use when throwing
      Returns:
      the value
      Throws:
      NoSuchElementException - if no value is present
    • optional

      default Optional<T> optional()
      Returns:
      an Optional wrapping this value.
    • isNull

      default boolean isNull()
      Returns:
      true if the underlying value is null.
    • isNullable

      default boolean isNullable()
      If false then get() is guaranteed to never return null.
      Returns:
      true if this observable can be null
    • isEqualTo

      default boolean isEqualTo(@Nullable T value)
      Returns true if the underlying value is equal to the given one. Note that null == null.
      Parameters:
      value - the value
      Returns:
      true if the underlying value is equal to the given one
    • isNotEqualTo

      default boolean isNotEqualTo(@Nullable T value)
      Returns true if the underlying value is NOT equal to the given one. Note that null == null.
      Parameters:
      value - the value
      Returns:
      true if the underlying value is NOT equal to the given one
    • observer

      Observer<T> observer()
      Returns:
      an Observer notified each time the observed value may have changed
    • addListener

      default boolean addListener(Runnable listener)
      Description copied from interface: Observer
      Adds listener to this Observer. Adding the same listener a second time has no effect.
      Specified by:
      addListener in interface Observer<T>
      Parameters:
      listener - the listener to add
      Returns:
      true if this observer did not already contain the specified listener
    • removeListener

      default boolean removeListener(Runnable listener)
      Description copied from interface: Observer
      Removes listener from this Observer
      Specified by:
      removeListener in interface Observer<T>
      Parameters:
      listener - the listener to remove
      Returns:
      true if this observer contained the specified listener
    • addConsumer

      default boolean addConsumer(Consumer<? super T> consumer)
      Description copied from interface: Observer
      Adds consumer to this Observer. Adding the same consumer a second time has no effect.
      Specified by:
      addConsumer in interface Observer<T>
      Parameters:
      consumer - the consumer to add
      Returns:
      true if this observer did not already contain the specified consumer
    • removeConsumer

      default boolean removeConsumer(Consumer<? super T> consumer)
      Description copied from interface: Observer
      Removes consumer from this Observer
      Specified by:
      removeConsumer in interface Observer<T>
      Parameters:
      consumer - the consumer to remove
      Returns:
      true if this observer contained the specified consumer
    • addWeakListener

      default boolean addWeakListener(Runnable listener)
      Description copied from interface: Observer
      Uses a WeakReference, adding listener does not prevent it from being garbage collected. Adding the same listener a second time has no effect.
      Specified by:
      addWeakListener in interface Observer<T>
      Parameters:
      listener - the listener
      Returns:
      true if this observer did not already contain the specified listener
    • removeWeakListener

      default boolean removeWeakListener(Runnable listener)
      Description copied from interface: Observer
      Removes listener from this Observer
      Specified by:
      removeWeakListener in interface Observer<T>
      Parameters:
      listener - the listener to remove
      Returns:
      true if this observer contained the specified listener
    • addWeakConsumer

      default boolean addWeakConsumer(Consumer<? super T> consumer)
      Description copied from interface: Observer
      Uses a WeakReference, adding consumer does not prevent it from being garbage collected. Adding the same consumer a second time has no effect.
      Specified by:
      addWeakConsumer in interface Observer<T>
      Parameters:
      consumer - the consumer
      Returns:
      true if this observer did not already contain the specified consumer
    • removeWeakConsumer

      default boolean removeWeakConsumer(Consumer<? super T> consumer)
      Description copied from interface: Observer
      Removes consumer from this Observer.
      Specified by:
      removeWeakConsumer in interface Observer<T>
      Parameters:
      consumer - the consumer to remove
      Returns:
      true if this observer contained the specified consumer