Use dedicated method for loading Config, clean exception types and handling

This commit is contained in:
Reperak 2021-11-07 20:57:50 -06:00
parent 0fa9ceef8e
commit d11b9a97a4
No known key found for this signature in database
GPG key ID: 12F30C9BA6950C0C
2 changed files with 21 additions and 8 deletions

View file

@ -3,22 +3,29 @@ package codes.ztereohype.ztereomusic.database;
import lombok.Getter;
import net.shadew.json.Json;
import net.shadew.json.JsonNode;
import net.shadew.json.JsonSyntaxException;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.Map;
public class Config {
private @Getter final Map<String, String> propreties = new HashMap<>();
private final String path;
private @Getter Map<String, String> propreties = new HashMap<>();
private String path;
public static Config loadFrom(String path) throws JsonSyntaxException, FileNotFoundException {
Config config = new Config();
public Config(String pathname) throws Exception {
Json json5 = Json.json5();
JsonNode tree = json5.parse(new File(pathname));
this.path = pathname;
JsonNode tree = json5.parse(new File(path));
config.path = path;
for (String key : tree.keys()) {
propreties.put(key, tree.get(key).asString());
config.getPropreties().put(key, tree.get(key).asString());
}
return config;
}
}