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
Represents an option of the application's configuration.
- See Also:
-
Field Summary
Fields inherited from class dev.prozilla.pine.common.event.EventDispatcher
logger
-
Constructor Summary
ConstructorsConstructorDescriptionConfigOption
(T value) Creates a config option without a validator.ConfigOption
(T value, Predicate<T> validator) Creates a config option with a validator. -
Method Summary
Modifier and TypeMethodDescriptionvoid
copyFrom
(ConfigOption<T> otherOption) Copies the value of another option to this option.void
copyTo
(ConfigOption<T> otherOption) Copies the value of this option to another option.boolean
exists()
get()
Returns the value of this option.boolean
isValidValue
(T value) Checks whether a value is a valid value for this option.void
onChange
(EventListener listener) void
onReset
(EventListener listener) void
read
(EventListener listener) Invokes an event listener once and then every time this option changes.void
reset()
Resets this option to its initial value.void
Sets the value of this option.Methods inherited from class dev.prozilla.pine.common.event.EventDispatcher
addListener, destroy, invoke, removeListener, setLogger
-
Constructor Details
-
ConfigOption
Creates a config option without a validator.- Parameters:
value
- Initial value
-
ConfigOption
Creates a config option with a validator.- Parameters:
value
- Initial value- Throws:
IllegalArgumentException
- Ifvalidator
does not evaluate totrue
for the initial value.
-
-
Method Details
-
get
Returns the value of this option. -
set
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
Copies the value of this option to another option. -
copyFrom
Copies the value of another option to this option. -
isValidValue
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
Invokes an event listener once and then every time this option changes.- Parameters:
listener
- Listener to invoke
-
onChange
-
onReset
-