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 | package Torello.Browser.JsonAST;
import Torello.JSON.ReadJSON;
import javax.json.JsonObject;
/**
* Extracts the Json Property {@code "name"} from the input {@link JsonObject}. When building the
* AST from the CDP JSON spec files, objecs which are located in a {@link Domain Domain's}
* {@code "types"} array will differ slightly in that they will not have a {@code "name"} property
* at all. Intead {@code "types"}, which are constructed into instances of class {@link TypeNode},
* will have an Json Property named {@link TypeNode#name "id"} instead.
*/
@Torello.JavaDoc.Annotations.StaticFunctional
@Torello.JavaDoc.Annotations.JDHeaderBackgroundImg(EmbedTagFileID="CONSTRUCTOR_JDHBI")
public class Helper$Name
{
private Helper$Name() { }
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
// this.name **OR** this.id
// *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
static String getName(final Entity THIS, final JsonObject jo)
{
// getString(JsonObject jo, String propertyName, boolean isOptional, boolean throwOnNull)
final String name = ReadJSON.getString(jo, "name", true, true);
final String id = ReadJSON.getString(jo, "id", true, true);
final int count =
((name == null) ? 0 : 1) + // For a "Command TCE", "Event TCE", and **ALL** PPR
((id == null) ? 0 : 1); // For a "Type TCE"
if (count != 1) THIS.verifyThrow(
"Precisely one of these properties MUST contain a NON-NULL String:\n" +
"name: [" + name + "], id: [" + id + "]\n" +
"Apparently there were [" + count + "] set."
);
return (id != null)
? id // Sub-Class is guaranteed to be a "Type TCE"
: name; // **ANY** PPR, a "Command-TCE" or "Event-TCE"
}
}
|