Package pi.config

Class ConfigLoader

java.lang.Object
pi.config.ConfigLoader
Direct Known Subclasses:
Configuration

public class ConfigLoader extends Object
Konfigurationsklasse, die mehrere Konfigurationsgruppen verwaltet und das Laden und Speichern von Einstellungen übernimmt.
Since:
0.42.0
Author:
Steffen Wilke, Matthias Wilke, Josef Friedrich
  • Constructor Summary

    Constructors
    Constructor
    Description
    ConfigLoader(String path, ConfigGroup... configurationGroups)
    Constructs a new instance of the Configuration class using the specified file name.
    ConfigLoader(Path path, ConfigGroup... configurationGroups)
    Initializes a new instance of the Configuration class.
    ConfigLoader(ConfigGroup... configurationGroups)
    Initializes a new instance of the Configuration class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    add(ConfigGroup... groups)
    Adds the specified configuration group to the configuration.
    void
    Löscht die Konfigurationsdatei, falls sie existiert.
    Gets all ConfigurationGroups from the configuration.
    <T extends ConfigGroup>
    T
    getGroup(Class<T> groupClass)
    Gets the strongly typed configuration group if it was previously added to the configuration.
    getGroup(String prefix)
    Ruft eine Konfigurationsgruppe basierend auf ihrem Präfix ab.
    void
    Versucht, die Konfiguration aus der Datei im Anwendungsordner zu laden.
    Ruft den Pfad der Datei ab, in der diese Konfiguration gespeichert ist.
    void
    Saves this configuration to a file with the specified name of this instance (engine-pi.properties is the engines default config file).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ConfigLoader

      public ConfigLoader(ConfigGroup... configurationGroups)
      Initializes a new instance of the Configuration class.
      Parameters:
      configurationGroups - The configuration groups managed by this instance.
    • ConfigLoader

      public ConfigLoader(String path, ConfigGroup... configurationGroups)
      Constructs a new instance of the Configuration class using the specified file name. This constructor converts the provided file name string into a Path object and delegates the initialization to another constructor.
      Parameters:
      path - The path of the file from which to load the settings.
      configurationGroups - The configuration groups managed by this instance.
    • ConfigLoader

      public ConfigLoader(Path path, ConfigGroup... configurationGroups)
      Initializes a new instance of the Configuration class.
      Parameters:
      path - The path of the file from which to load the settings.
      configurationGroups - The configuration groups managed by this instance.
  • Method Details

    • getGroup

      public <T extends ConfigGroup> T getGroup(Class<T> groupClass)
      Gets the strongly typed configuration group if it was previously added to the configuration.
      Type Parameters:
      T - The type of the config group.
      Parameters:
      groupClass - The class that provides the generic type for this method.
      Returns:
      The configuration group of the specified type or null if none can be found.
    • getGroup

      public ConfigGroup getGroup(String prefix)
      Ruft eine Konfigurationsgruppe basierend auf ihrem Präfix ab.
      Parameters:
      prefix - das Präfix der gesuchten Konfigurationsgruppe
      Returns:
      die gefundene ConfigGroup
      Throws:
      RuntimeException - wenn keine Konfigurationsgruppe mit dem angegebenen Präfix gefunden wird
    • getConfigurationGroups

      public List<ConfigGroup> getConfigurationGroups()
      Gets all ConfigurationGroups from the configuration.
      Returns:
      All config groups.
    • add

      public void add(ConfigGroup... groups)
      Adds the specified configuration group to the configuration.
      Parameters:
      groups - The group to add.
    • path

      @Getter public Path path()
      Ruft den Pfad der Datei ab, in der diese Konfiguration gespeichert ist.
      Returns:
      Der Pfad zur Konfigurationsdatei.
      See Also:
    • load

      public void load()
      Versucht, die Konfiguration aus der Datei im Anwendungsordner zu laden.

      Wenn keine vorhanden ist, versucht es, die Datei aus einem beliebigen Ressourcenordner zu laden. Wenn keine vorhanden ist, erstellt es eine neue Konfigurationsdatei im Anwendungsordner.

    • save

      public void save()
      Saves this configuration to a file with the specified name of this instance (engine-pi.properties is the engines default config file).
      See Also:
      • path()
      • DEFAULT_CONFIGURATION_FILE_NAME
    • deleteConfigFile

      public void deleteConfigFile()
      Löscht die Konfigurationsdatei, falls sie existiert.

      Diese Methode versucht, die Konfigurationsdatei unter dem durch path() definierten Pfad zu löschen. Falls die Datei nicht existiert, wird keine Aktion durchgeführt.

      Throws:
      RuntimeException - falls beim Löschen der Datei ein Fehler auftritt