99import java .util .Map ;
1010import java .util .concurrent .ConcurrentHashMap ;
1111
12+ /**
13+ * Represents a configuration manager that handles loading, saving, and managing configuration fields.
14+ * It uses YAML files for storage and provides methods to add fields, retrieve values, and reload configurations.
15+ */
1216public class Config {
1317
1418 private final ExtendedFancyLogger logger ;
@@ -23,20 +27,35 @@ public Config(ExtendedFancyLogger logger, String configFilePath) {
2327 this .values = new ConcurrentHashMap <>();
2428 }
2529
30+ /**
31+ * Adds a configuration field to the manager.
32+ *
33+ * @param field the configuration field to add
34+ */
2635 public void addField (ConfigField <?> field ) {
2736 fields .put (field .path (), field );
2837 }
2938
39+ /**
40+ * Retrieves the value of a configuration field by its path.
41+ *
42+ * @param path the path of the configuration field
43+ * @param <T> the type of the field value
44+ * @return the value of the configuration field or null if not found
45+ */
3046 public <T > T get (String path ) {
3147 ConfigField <?> field = fields .get (path );
3248 if (field != null ) {
3349 Object value = values .computeIfAbsent (path , k -> field .defaultValue ());
3450 return (T ) field .type ().cast (value );
3551 }
3652
37- throw new IllegalArgumentException ( "No field found for path: " + path ) ;
53+ return null ;
3854 }
3955
56+ /**
57+ * Reloads the configuration from the file.
58+ */
4059 public void reload () {
4160 if (!configFile .exists ()) {
4261 if (!configFile .mkdirs ()) {
0 commit comments