use of org.rx.annotation.ErrorCode in project rxlib by RockyLOMO.
the class YamlConfiguration method readAs.
@ErrorCode("keyError")
@ErrorCode("partialKeyError")
public synchronized <T> T readAs(String key, Class<T> type, boolean throwOnEmpty) {
Map<String, Object> tmp = yaml;
if (key == null) {
return convert(tmp, type);
}
Object val;
if ((val = tmp.get(key)) != null) {
return convert(val, type);
}
StringBuilder buf = new StringBuilder();
String[] splits = Strings.split(key, Constants.CONFIG_KEY_SPLITS);
int c = splits.length - 1;
for (int i = 0; i <= c; i++) {
if (buf.length() > 0) {
buf.append(Constants.CONFIG_KEY_SPLITS);
}
String k = buf.append(splits[i]).toString();
if ((val = tmp.get(k)) == null) {
continue;
}
if (i == c) {
return convert(val, type);
}
if ((tmp = as(val, Map.class)) == null) {
throw new ApplicationException("partialKeyError", values(k, type));
}
buf.setLength(0);
}
if (throwOnEmpty) {
throw new ApplicationException("keyError", values(key, type));
}
return null;
}
Aggregations