Class ObservableProperty<T>

All Implemented Interfaces:
Destructible
Direct Known Subclasses:
ConfigOption, SelectionProperty

public class ObservableProperty<T> extends MutableProperty<T> implements Destructible
A property that triggers observers whenever its value changes.
  • Field Details

    • logger

      protected Logger logger
  • Constructor Details

    • ObservableProperty

      public ObservableProperty()
      Creates an observable property without an initial value.
    • ObservableProperty

      public ObservableProperty(T initialValue)
      Creates an observable property with an initial value.
      Parameters:
      initialValue - The initial value
  • Method Details

    • read

      public void read(Observer<T> reader)
      Adds an observer that is immediately called with the current value.

      This is the equivalent of calling MutableProperty.getValue(), then doing something with that value, and then adding an observer which does the same thing each time the value changes.

      Parameters:
      reader - The observer
    • addObserver

      public Observer<T> addObserver(Observer<T> observer)
    • removeObserver

      public void removeObserver(Observer<T> observer)
    • setLogger

      public void setLogger(Logger logger)
      Sets the logger of this property, which is used to log errors thrown by observers.
    • onValueChange

      protected void onValueChange(T oldValue, T newValue)
      Triggers all observers with the newValue whenever the value changes.
      Overrides:
      onValueChange in class MutableProperty<T>
      Parameters:
      oldValue - The previous value
      newValue - The new value
    • getLogger

      protected Logger getLogger()
    • destroy

      public void destroy()
      Removes all observers.
      Specified by:
      destroy in interface Destructible