Skip to content

Commit 54a45ef

Browse files
config: Add some javadocs
1 parent a744e6e commit 54a45ef

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

libraries/config/src/main/java/com/fancyinnovations/config/Config.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
import java.util.Map;
1010
import 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+
*/
1216
public 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()) {

libraries/config/src/main/java/com/fancyinnovations/config/ConfigField.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package com.fancyinnovations.config;
22

3+
/**
4+
* Represents a field in a configuration file.
5+
*
6+
* @param <T> the type of the field value
7+
* @param path the path to the field in the configuration file (e.g., "notifications.mute_version")
8+
* @param description a description of the field
9+
* @param forRemoval indicates if this field should be removed
10+
* @param defaultValue the default value of the field
11+
* @param type the class type of the field value
12+
*/
313
public record ConfigField<T>(
414
String path,
515
String description,

0 commit comments

Comments
 (0)