Package de.exlll.configlib
Interface FileConfigurationStore<T>
- Type Parameters:
T- the configuration type
public interface FileConfigurationStore<T>
Instances of this class save and load configurations using files.
-
Method Summary
-
Method Details
-
save
Saves a configuration instance to the given file.- Parameters:
configuration- the configurationconfigurationFile- the file the configuration is saved to- Throws:
ConfigurationException- if the configuration contains invalid values or cannot be serializedNullPointerException- if any argument is nullRuntimeException- if writing the configuration throws an exception
-
load
Loads a configuration from the given file.- Parameters:
configurationFile- the file the configuration is loaded from- Returns:
- a newly created configuration initialized with values taken from the configuration file
- Throws:
ConfigurationException- if the configuration cannot be deserializedIllegalArgumentException- if the file does not exist or is not a regular fileNullPointerException- ifconfigurationFileis nullRuntimeException- if reading the configuration throws an exception
-
update
Updates the configuration file.- If the file does not exist, it is created and populated with the default values with which the fields of the configuration have been initialized. If the configuration is of record type, the default values are either chosen to be the default values of its component types (i.e. zero for primitive numbers, null for references, etc) or, if the record defines a constructor with no parameters, the values with which this constructor initializes the components of the record.
- Otherwise, if the file exists, a new configuration instance is created, initialized with the values taken from the configuration file, and immediately saved to reflect potential changes of the configuration type.
- Parameters:
configurationFile- the configuration file that is updated- Returns:
- a newly created configuration initialized with values taken from the configuration file or a default configuration
- Throws:
ConfigurationException- if the configuration cannot be deserializedNullPointerException- ifconfigurationFileis nullRuntimeException- if loading or saving the configuration throws an exception
-