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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110 | package Torello.Browser.JsonAST;
import Torello.JSON.ReadJSON;
import Torello.Java.Additional.Ret3;
import Torello.Java.ReadOnly.ReadOnlyList;
import Torello.Java.ReadOnly.ReadOnlyArrayList;
import Torello.Java.ReadOnly.ROArrayListBuilder;
import javax.json.JsonObject;
import javax.json.JsonArray;
/**
* Extracts the complete list of {@link TypeNode}, {@link CommandNode} and {@link EventNode} from
* the {@link JsonObject} of a {@link Domain} definition. This class parsed the {@code JsonArray}
* instances inside the JSON which have the names {@code "types", "commands", "events"}.
*/
@Torello.JavaDoc.Annotations.StaticFunctional
@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="CONSTRUCTOR_JDHBI")
public class Helper$GetTCELists
{
private Helper$GetTCELists() { }
static Ret3
<
ReadOnlyList<TypeNode>,
ReadOnlyList<CommandNode>,
ReadOnlyList<EventNode>
>
get(final Domain d, final JsonObject jo)
{
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// Types, Commands & Events
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
final ReadOnlyList<TypeNode> types;
final ReadOnlyList<CommandNode> commands;
final ReadOnlyList<EventNode> events;
// ReadJSON.getJsonObject
// (JsonObject jo, String propertyName, boolean isOptional, boolean throwOnNull)
final JsonArray typesJA = ReadJSON.getJsonArray(jo, "types", true, true);
final JsonArray commandsJA = ReadJSON.getJsonArray(jo, "commands", true, true);
final JsonArray eventsJA = ReadJSON.getJsonArray(jo, "events", true, true);
final java.util.Comparator<Entity> sorterTCE = (Entity a, Entity b) ->
a.name.compareTo(b.name);
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// TYPES
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
if (typesJA == null)
types = ReadOnlyArrayList.emptyROAL();
else
{
int i = 0;
ROArrayListBuilder<TypeNode> roalb = new ROArrayListBuilder<>();
for (JsonObject typeJO : typesJA.getValuesAs(JsonObject.class))
roalb.add(new TypeNode(d, typeJO, i++));
roalb.sort(sorterTCE);
types = roalb.build();
}
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// COMMANDS
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
if (commandsJA == null)
commands = ReadOnlyArrayList.emptyROAL();
else
{
int i = 0;
ROArrayListBuilder<CommandNode> roalb = new ROArrayListBuilder<>();
for (final JsonObject commandJO : commandsJA.getValuesAs(JsonObject.class))
roalb.add(new CommandNode(d, commandJO, i++));
roalb.sort(sorterTCE);
commands = roalb.build();
}
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// EVENTS
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
if (eventsJA == null)
events = ReadOnlyArrayList.emptyROAL();
else
{
int i = 0;
ROArrayListBuilder<EventNode> roalb = new ROArrayListBuilder<>();
for (final JsonObject eventJO : eventsJA.getValuesAs(JsonObject.class))
roalb.add(new EventNode(d, eventJO, i++));
roalb.sort(sorterTCE);
events = roalb.build();
}
return new Ret3<>(types, commands, events);
}
}
|