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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
package Torello.JavaDoc;

import Torello.Java.ReadOnly.ReadOnlyMap;
import Torello.Java.ReadOnly.ROTreeMapBuilder;
import Torello.Java.ReadOnly.ReadOnlyTreeMap;

import Torello.JDUInternal.Features.STATS.StatsInternal;

import java.util.Map;

/**
 * Maintains a suite of statistics about all Java project-wide source-code files.
 * 
 * <BR />As the Upgrade Processors are executed, this class maintains a few statistics about the
 * build, and produces the {@code Stats} HTML instance, which is subsequently linked to a
 * {@code 'Stats'} button on output Java Doc Web-Pages - <I>and also returned to the user after
 * calling the ugrader</I>.
 * 
 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=UPSTATS>
 */
public class Stats implements java.io.Serializable
{
    // ********************************************************************************************
    // ********************************************************************************************
    // Static-Constants
    // ********************************************************************************************
    // ********************************************************************************************

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


    // ********************************************************************************************
    // ********************************************************************************************
    // An Instance-Constant
    // ********************************************************************************************
    // ********************************************************************************************


    // Package-Level instances of 'Stats' will have their package-names saved here.
    // For the "Complete-Project" Stats instance, this will be null.

    public final String packageName;


    // ********************************************************************************************
    // ********************************************************************************************
    // ReadOnlyMap's
    // ********************************************************************************************
    // ********************************************************************************************


    // Each Package has it's own instance of 'Stats'
    // For a Package-Level instances of 'Stats' - this field will be null.

    public final ReadOnlyMap<String, Stats> packageStatsMap;

    // A Pointer to the "Project-Global Embed-Tags Map"
    public final ReadOnlyMap<String, String> globalTagsMap;

    // A Count-Total for the "Project-Global Embed-Tags Map"
    public final ReadOnlyMap<String, Integer> globalTagsCount;


    // A reference pointer to the "Package-Local Embed-Tag Map", (ID's ==> FileNames)
    // NOTE: For the top-level main 'Stats' instance, this will remain null

    public final ReadOnlyMap<String, String> packageTagsMap;


    // Keeps a count of the use of all "Package-Local Embed-Tags"
    // NOTE: For the top-level main 'Stats' instance, this will remain null

    public final ReadOnlyMap<String, Integer> packageTagsCount;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats Fields: BASIC
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of lines of {@code '.java'} files. */
    public final int numLines;

    /** Maintains A count of the total number of bytes of {@code '.java'} files. */
    public final int numBytes;

    /** Maintains A count of the total number of HiLited HTML {@code <DIV>} Elements. */
    public final int numHiLitedDivs;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: Entity (METHOD, FIELD, CONSTRUCTOR, ANNOTATION_ELEM, ENUM_CONSTANT)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of methods found during the upgrade. */
    public final int numMethods;

    /** Maintains A count of the total number of constructors found during the upgrade. */
    public final int numConstructors;

    /** Maintains A count of the total number of fields found during the upgrade. */
    public final int numFields;

    /** Maintains A count of the total number of annotation-elements found during the upgrade. */
    public final int numAnnotationElems;

    /** Maintains A count of the total number of enum-constants found during the upgrade. */
    public final int numEnumConstants;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: HILITED-Entity (METHOD, FIELD, CONSTRUCTOR, ANNOTATION_ELEM, ENUM_CONSTANT)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of method bodies hilited by the upgrader. */
    public final int numHiLitedMethods;

    /** Maintains A count of the total number of constructor bodies hilited by the upgrader. */
    public final int numHiLitedConstructors;

    /** Maintains A count of the total number of field declarations hilited by the upgrader. */
    public final int numHiLitedFields;

    /** A count of the total number of annotation-element declarations hilited by the upgrader. */
    public final int numHiLitedAnnotationElems;

    /** A count of the total number of enumeration-constant declarations hilited by the upgrader.*/
    public final int numHiLitedEnumConstants;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: DOCUMENTED-Entity (METHOD, FIELD, CONSTRUCTOR, ANNOTATION_ELEM, ENUM_CONSTANT)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of methods that were documented by Java Doc. */
    public final int numDocumentedMethods;

    /** Maintains A count of the total number of constructors that were documented by Java Doc. */
    public final int numDocumentedConstructors;

    /** Maintains A count of the total number of fields that were documented by Java Doc. */
    public final int numDocumentedFields;

    /** A count of the total number of annotation-elements that were documented by Java Doc. */
    public final int numDocumentedAnnotationElems;

    /** A count of the total number of annotation-elements that were documented by Java Doc. */
    public final int numDocumentedEnumConstants;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: STATIC-Entity (METHOD, FIELD)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of {@code static} methods found during the upgrade. */
    public final int numStaticMethods;

    /** Maintains A count of the total number of {@code static} fields found during the upgrade. */
    public final int numStaticFields;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: FINAL-Entity (METHOD, FIELD, CONSTRUCTOR)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of {@code final} methods found by the upgrade. */
    public final int numFinalMethods;

    /** Maintains A count of the total number of {@code final} constructors found by the upgrader. */
    public final int numFinalConstructors;

    /** Maintains A count of the total number of {@code final} fields found by the upgrader. */
    public final int numFinalFields;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: PUBLIC-Entity (METHOD, FIELD, CONSTRUCTOR)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of {@code public} methods found by the upgrader. */
    public final int numPublicMethods;

    /** Maintains A count of the total number of {@code public} constructors found by the upgrader.*/
    public final int numPublicConstructors;

    /** Maintains A count of the total number of {@code public} fields found by the upgrader. */
    public final int numPublicFields;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: PROTECTED-Entity (METHOD, FIELD, CONSTRUCTOR)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains The total number of {@code protected} methods found during the upgrade. */
    public final int numProtectedMethods;

    /** Maintains The total number of {@code protected} constructors found during the upgrade. */
    public final int numProtectedConstructors;

    /** Maintains The total number of {@code protected} fields found during the upgrade. */
    public final int numProtectedFields;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: PRIVATE-Entity (METHOD, FIELD, CONSTRUCTOR)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains The total number of {@code private} methods found during the upgrade. */
    public final int numPrivateMethods;

    /** Maintains The total number of {@code private} constructors found during the upgrade. */
    public final int numPrivateConstructors;

    /** Maintains The total number of {@code private} fields found during the upgrade. */
    public final int numPrivateFields;


    // ********************************************************************************************
    // ********************************************************************************************
    // Stats: OTHER-Entity (FIELD only)
    // ********************************************************************************************
    // ********************************************************************************************


    /** Maintains A count of the total number of {@code transient} fields found during the upgrade.*/
    public final int numTransientFields;

    /** Maintains A count of the total number of {@code volatile} fields found during the upgrade. */
    public final int numVolatileFields;


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


    public Stats(final StatsInternal si)
    {
        // null for the "Top-Level" instance.  For 'Stats' instances that are used to represent
        // Java-Packages, the 'packageName' field for a 'StatsInternal' instance is, literally, 
        // just the Name-as-a-String of the Java-Package being described.

        this.packageName = si.packageName;


        // This is never null - even for Package-Level instance.  Package-Level instances are 
        // actually instantiated, internally, in class 'StatsInternal', and they utilize a private
        // constructor.  The Private-Constructor uses the Top-Level 'StatsInternal' instance to 
        // make sure that the "globalTagsMap" reference from the 'Top-Level-Instance' is properly
        // passed to all of the Package-Level (children) instances within the container.
        // 
        // Note: Again, the "container" is just the lone Top-Level-Instance.  The 'Stats' and the
        //       'StatsInternal' data-structures are mirrors, and neither of them are *TREES* of
        //       Java-Package 'Stats' (Statistics) instances, instead they have a single, internal,
        //       list that contains all of the 'Stats' and 'StatsInternal' instances which are
        //       associated with a User's Packages.
        // 
        // Also: This 'Map' is nothing but the POJO-Version of the users
        // 'external-html-ids.properties' file for the "Global <EMBED>-Tags"
    
        this.globalTagsMap  = si.globalTagsMap;

        // A little bit of effciency
        this.globalTagsCount = (si.globalTagsCount.size() > 0)
            ? new ReadOnlyTreeMap<>(si.globalTagsCount)
            : ReadOnlyTreeMap.emptyROTM();

        this.packageTagsMap = si.packageTagsMap;

        // This is null for the "Global, Top-Level" Stats-Instance
        this.packageTagsCount = (si.packageTagsCount == null)
            ? null
            : (si.packageTagsCount.size() > 0)
                ? new ReadOnlyTreeMap<>(si.packageTagsCount)
                : ReadOnlyTreeMap.emptyROTM();

        // This Field shall contain a map of "Package-Name" to "Package Stats-Instances"
        if (si.packageStatsMap == null) this.packageStatsMap = null;
 
        else
        {
            final ROTreeMapBuilder<String, Stats> rotmb = new ROTreeMapBuilder<>();

            // public final Map<String, Stats> packageStatsMap;
            for (final String key : si.packageStatsMap.keySet())
            {
                final StatsInternal siInner     = si.packageStatsMap.get(key);
                final Stats         statsInner  = new Stats(siInner);

                rotmb.put(key, statsInner);
            }

            this.packageStatsMap = rotmb.build();
        }

        this.numLines                       = si.numLines();
        this.numBytes                       = si.numBytes();
        this.numHiLitedDivs                 = si.numHiLitedDivs();
    
        this.numMethods                     = si.numMethods();
        this.numConstructors                = si.numConstructors();
        this.numFields                      = si.numFields();
        this.numAnnotationElems             = si.numAnnotationElems();
        this.numEnumConstants               = si.numEnumConstants();
    
        this.numHiLitedMethods              = si.numHiLitedMethods();
        this.numHiLitedConstructors         = si.numHiLitedConstructors();
        this.numHiLitedFields               = si.numHiLitedFields();
        this.numHiLitedAnnotationElems      = si.numHiLitedAnnotationElems();
        this.numHiLitedEnumConstants        = si.numHiLitedEnumConstants();
    
        this.numDocumentedMethods           = si.numDocumentedMethods();
        this.numDocumentedConstructors      = si.numDocumentedConstructors();
        this.numDocumentedFields            = si.numDocumentedFields();
        this.numDocumentedAnnotationElems   = si.numDocumentedAnnotationElems();
        this.numDocumentedEnumConstants     = si.numDocumentedEnumConstants();
    
        this.numStaticMethods               = si.numStaticMethods();
        this.numStaticFields                = si.numStaticFields();

        this.numFinalMethods                = si.numFinalMethods();
        this.numFinalConstructors           = si.numFinalConstructors();
        this.numFinalFields                 = si.numFinalFields();
    
        this.numPublicMethods               = si.numPublicMethods();
        this.numPublicConstructors          = si.numPublicConstructors();
        this.numPublicFields                = si.numPublicFields();

        this.numProtectedMethods            = si.numProtectedMethods();
        this.numProtectedConstructors       = si.numProtectedConstructors();
        this.numProtectedFields             = si.numProtectedFields();
    
        this.numPrivateMethods              = si.numPrivateMethods();
        this.numPrivateConstructors         = si.numPrivateConstructors();
        this.numPrivateFields               = si.numPrivateFields();

        this.numTransientFields             = si.numTransientFields();
        this.numVolatileFields              = si.numVolatileFields();
    }


    // ********************************************************************************************
    // ********************************************************************************************
    // To String
    // ********************************************************************************************
    // ********************************************************************************************


    /**
     * Generates a {@code String} that enapsulates all of the counters / running-totals inside
     * this data statistic class.
     * 
     * @return A {@code String} representation of this class.  Only includes statistics about
     * use of methods, constructors, fields etc...  <B>DOES NOT INCLUDE</B> statistics regarding
     * the use of the {@code <EMBED CLASS='external-html' ...>} tags.
     */
    public String toString()
    { return Torello.JDUInternal.Features.STATS.API_Stats.toString(this); }
}