Interface Mutable<T>

Type Parameters:
T - the value type
All Superinterfaces:
Observable<T>, Observer<T>
All Known Subinterfaces:
EntityEditModel.EditableEntity, FilterComboBoxModel.ComboBoxItems<T>, FilterComboBoxModel.NullItem<T>, FilterModel.Items<T>, MultiItemSelection.Indexes, MultiItemSelection.Items<R>
All Known Implementing Classes:
NullableToggleButtonModel.ToggleState

public interface Mutable<T> extends Observable<T>
A wrapper for a mutable 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();

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

       @Override
       public void set(String value) {
           person.setName(value);
       }

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

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

    • set

      void set(T value)
      Sets the value
      Parameters:
      value - the value to set
    • clear

      default void clear()
      Clears this Mutable instance by setting the value to null