Skip to content

Commit 971dafa

Browse files
authored
Merge pull request #3 from embeddedt/master
Add support for string list configs
2 parents 779d815 + ffa5e4b commit 971dafa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

src/main/java/com/falsepattern/lib/config/Config.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@
9191
String value();
9292
}
9393

94+
@Retention(RetentionPolicy.RUNTIME)
95+
@Target(ElementType.FIELD)
96+
@interface DefaultStringList {
97+
String[] value();
98+
}
99+
94100
@Retention(RetentionPolicy.RUNTIME)
95101
@Target(ElementType.FIELD)
96102
@interface Name {

src/main/java/com/falsepattern/lib/config/ConfigurationManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ private static void processConfigInternal(Class<?> configClass, String category,
155155
configClass.getName() + "! Using default value of " + defaultValue + "!");
156156
field.set(null, defaultValue);
157157
}
158+
} else if (fieldClass.isArray() && fieldClass.getComponentType().equals(String.class)) {
159+
val defaultValue = Optional.ofNullable(field.getAnnotation(Config.DefaultStringList.class)).map(Config.DefaultStringList::value).orElse((String[])field.get(null));
160+
var value = rawConfig.getStringList(name, category, defaultValue, comment, null, langKey);
161+
field.set(null, value);
158162
} else {
159163
throw new ConfigException("Illegal config field: " + field.getName() + " in " + configClass.getName() +
160164
": Unsupported type " + fieldClass.getName() +

0 commit comments

Comments
 (0)