forked from SteamWar/SteamWar
Improve YMLWrapper
This commit is contained in:
@@ -83,9 +83,15 @@ public abstract class YMLWrapper<M, ST, W> {
|
||||
return materialMapper.apply(getString(path, defaultValue).toUpperCase());
|
||||
}
|
||||
|
||||
public abstract List<String> getStringList(String path);
|
||||
public abstract <T> List<T> get(String path, Function<Object, List<T>> mapper);
|
||||
|
||||
public abstract List<Integer> getIntList(String path);
|
||||
public List<String> getStringList(String path) {
|
||||
return get(path, o -> (List<String>) o);
|
||||
}
|
||||
|
||||
public List<Integer> getIntList(String path) {
|
||||
return get(path, o -> (List<Integer>) o);
|
||||
}
|
||||
|
||||
public final List<ST> getSchematicTypeList(String path) {
|
||||
List<String> list = getStringList(path);
|
||||
|
||||
@@ -111,24 +111,16 @@ public class YMLWrapperImpl<M, ST, W> extends YMLWrapper<M, ST, W> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getStringList(String path) {
|
||||
public <T> List<T> get(String path, Function<Object, List<T>> mapper) {
|
||||
if (config == null) return Collections.emptyList();
|
||||
List<String> list = config.getStringList(pathPrefix + path);
|
||||
if (list.isEmpty()) {
|
||||
List<?> list = config.getList(pathPrefix + path);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getIntList(String path) {
|
||||
if (config == null) return Collections.emptyList();
|
||||
List<Integer> list = config.getIntegerList(pathPrefix + path);
|
||||
if (list.isEmpty()) {
|
||||
try {
|
||||
return Collections.unmodifiableList(mapper.apply(list));
|
||||
} catch (ClassCastException e) {
|
||||
return Collections.emptyList();
|
||||
} else {
|
||||
return Collections.unmodifiableList(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user