Class ConfigManager<T extends Serializable>

java.lang.Object
net.uku3lig.ukulib.config.ConfigManager<T>
Type Parameters:
T - The type of the config

public class ConfigManager<T extends Serializable> extends Object
Manages a config, by holding it, saving it and loading it.
  • Constructor Details

    • ConfigManager

      public ConfigManager(Class<T> configClass, ConfigSerializer<T> serializer, T config)
      Creates a manager.
      Parameters:
      configClass - The class of the config
      serializer - The serializer
      config - The initial config
    • ConfigManager

      public ConfigManager(Class<T> configClass, ConfigSerializer<T> serializer)
      Creates a manager which provides an initial config by deserializing the file.
      Parameters:
      configClass - The class of the config
      serializer - The serializer
  • Method Details

    • create

      public static <T extends Serializable> ConfigManager<T> create(Class<T> configClass, String name)
      Creates a default config manager, with a default config serializer. The config will be saved to and read from ./config/[name].toml (without the brackets).
      Type Parameters:
      T - The type of the config
      Parameters:
      configClass - The class of the config
      name - The name of the config, used for the filename
      Returns:
      The generated config manager
    • saveConfig

      public void saveConfig()
      Saves the stored config.
    • replaceConfig

      public void replaceConfig(T newConfig)
      Replaces the current config with a new one, serializing it in the process.
      Parameters:
      newConfig - The new config
    • defaultConfig

      public T defaultConfig()
      Creates a new default config, from a public no-arg constructor.
      Returns:
      The default config
    • getConfigClass

      public Class<T> getConfigClass()
      The class of the held config
      Returns:
      The class
    • getConfig

      public T getConfig()
      The config held by the manager.
      Returns:
      The config