-
Notifications
You must be signed in to change notification settings - Fork 0
/
StateLoader.java
60 lines (50 loc) · 1.71 KB
/
StateLoader.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
public class StateLoader {
private static Map<String, State> states = new ConcurrentHashMap<>();
public static State get(String name) {
return states.get(name);
}
public static void load() throws JsonSyntaxException, IOException {
StatusDto statusDto = new Gson().fromJson(new String(Files.readAllBytes(Paths.get("STATUS.JSON"))),
StatusDto.class);
for (Entry<String, StateDto> e : statusDto.status.entrySet()) {
String name = e.getKey();
StateDto stateDto = e.getValue();
String type = stateDto.type;
String url = stateDto.url;
List<String> parameters = stateDto.parameters;
State state = new State(type, url, parameters);
states.put(name, state);
}
}
static class StatusDto {
public Map<String, StateDto> status;
class StateDto {
public String type;
public String url;
public List<String> parameters;
}
}
static class State {
public String type;
public String url;
public List<String> parameters;
public State(String type, String url, List<String> parameters) {
this.type = type;
this.url = url;
this.parameters = parameters;
}
}
public static void main(String[] args) throws IOException {
load();
System.out.println(states);
}
}