From 54a45ef827c549b80fa1c5f7be2bce8033c238a0 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 19 Jul 2025 18:57:58 +0200 Subject: [PATCH] config: Add some javadocs --- .../com/fancyinnovations/config/Config.java | 21 ++++++++++++++++++- .../fancyinnovations/config/ConfigField.java | 10 +++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/libraries/config/src/main/java/com/fancyinnovations/config/Config.java b/libraries/config/src/main/java/com/fancyinnovations/config/Config.java index fd2990cd..2bee1eef 100644 --- a/libraries/config/src/main/java/com/fancyinnovations/config/Config.java +++ b/libraries/config/src/main/java/com/fancyinnovations/config/Config.java @@ -9,6 +9,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +/** + * Represents a configuration manager that handles loading, saving, and managing configuration fields. + * It uses YAML files for storage and provides methods to add fields, retrieve values, and reload configurations. + */ public class Config { private final ExtendedFancyLogger logger; @@ -23,10 +27,22 @@ public class Config { this.values = new ConcurrentHashMap<>(); } + /** + * Adds a configuration field to the manager. + * + * @param field the configuration field to add + */ public void addField(ConfigField field) { fields.put(field.path(), field); } + /** + * Retrieves the value of a configuration field by its path. + * + * @param path the path of the configuration field + * @param the type of the field value + * @return the value of the configuration field or null if not found + */ public T get(String path) { ConfigField field = fields.get(path); if (field != null) { @@ -34,9 +50,12 @@ public class Config { return (T) field.type().cast(value); } - throw new IllegalArgumentException("No field found for path: " + path); + return null; } + /** + * Reloads the configuration from the file. + */ public void reload() { if (!configFile.exists()) { if (!configFile.mkdirs()) { diff --git a/libraries/config/src/main/java/com/fancyinnovations/config/ConfigField.java b/libraries/config/src/main/java/com/fancyinnovations/config/ConfigField.java index 300b03bf..6a97d156 100644 --- a/libraries/config/src/main/java/com/fancyinnovations/config/ConfigField.java +++ b/libraries/config/src/main/java/com/fancyinnovations/config/ConfigField.java @@ -1,5 +1,15 @@ package com.fancyinnovations.config; +/** + * Represents a field in a configuration file. + * + * @param the type of the field value + * @param path the path to the field in the configuration file (e.g., "notifications.mute_version") + * @param description a description of the field + * @param forRemoval indicates if this field should be removed + * @param defaultValue the default value of the field + * @param type the class type of the field value + */ public record ConfigField( String path, String description,