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

    Modifier and Type
    Method
    Description
    load(Path configurationFile)
    Loads a configuration from the given file.
    void
    save(T configuration, Path configurationFile)
    Saves a configuration instance to the given file.
    update(Path configurationFile)
    Updates the configuration file.
  • Method Details

    • save

      void save(T configuration, Path configurationFile)
      Saves a configuration instance to the given file.
      Parameters:
      configuration - the configuration
      configurationFile - the file the configuration is saved to
      Throws:
      ConfigurationException - if the configuration contains invalid values or cannot be serialized
      NullPointerException - if any argument is null
      RuntimeException - if writing the configuration throws an exception
    • load

      T load(Path configurationFile)
      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 deserialized
      IllegalArgumentException - if the file does not exist or is not a regular file
      NullPointerException - if configurationFile is null
      RuntimeException - if reading the configuration throws an exception
    • update

      T update(Path configurationFile)
      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 deserialized
      NullPointerException - if configurationFile is null
      RuntimeException - if loading or saving the configuration throws an exception