Improve YMLWrapper

This commit is contained in:
2025-10-25 22:08:58 +02:00
parent e6dea72024
commit 4405d9c25d
3 changed files with 19 additions and 30 deletions
@@ -99,21 +99,12 @@ public class YMLWrapperImpl<ST> extends YMLWrapper<String, ST, String> {
}
@Override
public List<String> getStringList(String path) {
public <T> List<T> get(String path, Function<Object, List<T>> mapper) {
Object value = this.document.get(path);
if (value instanceof List) {
return Collections.unmodifiableList((List<String>) value);
} else {
return Collections.emptyList();
}
}
@Override
public List<Integer> getIntList(String path) {
Object value = this.document.get(path);
if (value instanceof List) {
return Collections.unmodifiableList((List<Integer>) value);
} else {
if (value == null) return Collections.emptyList();
try {
return Collections.unmodifiableList(mapper.apply(value));
} catch (ClassCastException e) {
return Collections.emptyList();
}
}