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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package Torello.Browser.JsonAST;

import Torello.JavaDoc.Annotations.LinkJavaSource;
import Torello.JavaDoc.Annotations.JDHeaderBackgroundImg;

import Torello.Java.ReadOnly.ReadOnlyList;
import Torello.Java.ReadOnly.ReadOnlySet;
import Torello.Java.ReadOnly.ReadOnlyTreeSet;

import java.util.Iterator;
import java.util.Objects;
import javax.json.JsonObject;

/**
 * An Java Object used within AST to symbolize or encapsulate the data present in any of the 
 * {@link JsonObject JsonObject's} found within a {@link Domain Domain's} {@code "events"} array.
 * <EMBED CLASS='external-html' DATA-FILE-ID=AST_TREES>
 */
@JDHeaderBackgroundImg(EmbedTagFileID="AST_NODES_JDHBI")
public class EventNode extends TCE implements java.io.Serializable
{
    // ********************************************************************************************
    // ********************************************************************************************
    // STATIC FINAL FIELDS
    // ********************************************************************************************
    // ********************************************************************************************


    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
    protected static final long serialVersionUID = 1;

    /**
     * The list of additional {@link JsonObject} properties that the parser should expect when
     * parsing {@code EventNode} objects from the JSON CDP specification files.
     */
    protected static final ReadOnlySet<String> EVENT_JSON_PROPERTIES_SET =
        new ReadOnlyTreeSet<>(String::compareTo, "name", "parameters");


    // ********************************************************************************************
    // ********************************************************************************************
    // Constant & Final Instance-Fields (Set by the Constructor)
    // ********************************************************************************************
    // ********************************************************************************************


    /** 
     * Collection of PPR (Parameter) instances that will be materialized as Java Event-Class fields
     * <EMBED CLASS='external-html' DATA-FILE-ID=EventNode.parameters>
     */
    public final ReadOnlyList<PPR> parameters;

    /** 
     * Flag indicating whether this EventNode represents a reified inner class in the CDP model. 
     * <EMBED CLASS='external-html' DATA-FILE-ID=EventNode.isReifiedInnerClass>
     */
    public final boolean isReifiedInnerClass;


    // ********************************************************************************************
    // ********************************************************************************************
    // Constructor
    // ********************************************************************************************
    // ********************************************************************************************


    // Constructs a class that represents a Java-Script 'type', 'command' or 'event'
    EventNode(
            // The domain to which this 'type', 'command' or 'event' belongs
            final Domain parent,

            // The JSON Object representation of this 'TCE'
            final JsonObject jo,

            // The JSON Array index from which this JSON Object was retrieved.
            final int index
        )
    {
        super(
            parent,
            jo,
            WhichTCE.Event,
            EVENT_JSON_PROPERTIES_SET,
            index
        );

        this.parameters             = Helper$GetPPRLists.get(this, jo, WhichPPR.Parameter);
        this.isReifiedInnerClass    = (this.parameters != null);


        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
        // EventNode → **MAY NOT** have a "type" JsonProperty ==> 100% pass / TRUE / invariant
        // *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***

        if (this.typeProp != null)
            verifyThrow("EventNode TCE illegally declares a \"type\" Json property.");

        // This check is IDENTICAL to (a subset of) the previous check.  Just here to remind you
        if (this.arrItemsTypeProp != null)
            verifyThrow("This has an array field, but it is a EventNode TCE");

        if (this.enumVals != null)
            verifyThrow("EventNode TCE illegally declares an \"enum\" Json property.");
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // toString
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Returns an {@code Iterator} that iterates the contents of the {@link #parameters} list.
     * 
     * @see #parameters
     * @see Torello.Java.Additional.RemoveUnsupportedIterator
     */
    public Iterator<PPR> iterator()
    { return this.parameters.iterator(); }

    /** Returns a {@code String} representation of {@code 'this'} instance. */
    @LinkJavaSource(handle="StringTCE")
    public String toString()
    { return StringTCE.get(this); }
}