Package pi.config
Class ConfigLoader
java.lang.Object
pi.config.ConfigLoader
- Direct Known Subclasses:
Configuration
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
ConstructorsConstructorDescriptionConfigLoader(String path, ConfigGroup... configurationGroups) Constructs a new instance of theConfigurationclass using the specified file name.ConfigLoader(Path path, ConfigGroup... configurationGroups) Initializes a new instance of theConfigurationclass.ConfigLoader(ConfigGroup... configurationGroups) Initializes a new instance of theConfigurationclass. -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(ConfigGroup... groups) Adds the specified configuration group to the configuration.voidLöscht die Konfigurationsdatei, falls sie existiert.Gets allConfigurationGroupsfrom the configuration.<T extends ConfigGroup>
TGets the strongly typed configuration group if it was previously added to the configuration.Ruft eine Konfigurationsgruppe basierend auf ihrem Präfix ab.voidload()Versucht, die Konfiguration aus der Datei im Anwendungsordner zu laden.path()Ruft den Pfad der Datei ab, in der diese Konfiguration gespeichert ist.voidsave()Saves this configuration to a file with the specified name of this instance (engine-pi.properties is the engines default config file).
-
Constructor Details
-
ConfigLoader
Initializes a new instance of theConfigurationclass.- Parameters:
configurationGroups- The configuration groups managed by this instance.
-
ConfigLoader
Constructs a new instance of theConfigurationclass using the specified file name. This constructor converts the provided file name string into aPathobject 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
Initializes a new instance of theConfigurationclass.- Parameters:
path- The path of the file from which to load the settings.configurationGroups- The configuration groups managed by this instance.
-
-
Method Details
-
getGroup
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
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
Gets allConfigurationGroupsfrom the configuration.- Returns:
- All config groups.
-
add
Adds the specified configuration group to the configuration.- Parameters:
groups- The group to add.
-
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
-