Class ConfigOption<T>

java.lang.Object
dev.prozilla.pine.common.event.EventDispatcher<ConfigOptionEvent>
dev.prozilla.pine.core.state.config.ConfigOption<T>
Type Parameters:
T - Type of the value of the option

public class ConfigOption<T> extends EventDispatcher<ConfigOptionEvent>
Represents an option of the application's configuration.
See Also:
  • Constructor Details

    • ConfigOption

      public ConfigOption(T value)
      Creates a config option without a validator.
      Parameters:
      value - Initial value
    • ConfigOption

      public ConfigOption(T value, Predicate<T> validator) throws IllegalArgumentException
      Creates a config option with a validator.
      Parameters:
      value - Initial value
      Throws:
      IllegalArgumentException - If validator does not evaluate to true for the initial value.
  • Method Details

    • get

      public T get()
      Returns the value of this option.
    • set

      public void set(T value)
      Sets the value of this option.
      Parameters:
      value - New value for this option
    • exists

      public boolean exists()
      Returns:
      true if the value is not null.
    • copyTo

      public void copyTo(ConfigOption<T> otherOption)
      Copies the value of this option to another option.
    • copyFrom

      public void copyFrom(ConfigOption<T> otherOption)
      Copies the value of another option to this option.
    • isValidValue

      public boolean isValidValue(T value)
      Checks whether a value is a valid value for this option.
      Parameters:
      value - Value to check.
      Returns:
      True if the value is valid
    • reset

      public void reset()
      Resets this option to its initial value.
    • read

      public void read(EventListener listener)
      Invokes an event listener once and then every time this option changes.
      Parameters:
      listener - Listener to invoke
    • onChange

      public void onChange(EventListener listener)
    • onReset

      public void onReset(EventListener listener)