001package Torello.JavaDoc;
002
003import Torello.Java.ReadOnly.ReadOnlyMap;
004import Torello.Java.ReadOnly.ROTreeMapBuilder;
005import Torello.Java.ReadOnly.ReadOnlyTreeMap;
006
007import Torello.JDUInternal.Features.STATS.StatsInternal;
008
009import java.util.Map;
010
011/**
012 * Maintains a suite of statistics about all Java project-wide source-code files.
013 * 
014 * <BR />As the Upgrade Processors are executed, this class maintains a few statistics about the
015 * build, and produces the {@code Stats} HTML instance, which is subsequently linked to a
016 * {@code 'Stats'} button on output Java Doc Web-Pages - <I>and also returned to the user after
017 * calling the ugrader</I>.
018 * 
019 * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=UPSTATS>
020 */
021public class Stats implements java.io.Serializable
022{
023    // ********************************************************************************************
024    // ********************************************************************************************
025    // Static-Constants
026    // ********************************************************************************************
027    // ********************************************************************************************
028
029    /** <EMBED CLASS='external-html' DATA-FILE-ID=SVUID> */
030    protected static final long serialVersionUID = 1;
031
032
033    // ********************************************************************************************
034    // ********************************************************************************************
035    // An Instance-Constant
036    // ********************************************************************************************
037    // ********************************************************************************************
038
039
040    // Package-Level instances of 'Stats' will have their package-names saved here.
041    // For the "Complete-Project" Stats instance, this will be null.
042
043    public final String packageName;
044
045
046    // ********************************************************************************************
047    // ********************************************************************************************
048    // ReadOnlyMap's
049    // ********************************************************************************************
050    // ********************************************************************************************
051
052
053    // Each Package has it's own instance of 'Stats'
054    // For a Package-Level instances of 'Stats' - this field will be null.
055
056    public final ReadOnlyMap<String, Stats> packageStatsMap;
057
058    // A Pointer to the "Project-Global Embed-Tags Map"
059    public final ReadOnlyMap<String, String> globalTagsMap;
060
061    // A Count-Total for the "Project-Global Embed-Tags Map"
062    public final ReadOnlyMap<String, Integer> globalTagsCount;
063
064
065    // A reference pointer to the "Package-Local Embed-Tag Map", (ID's ==> FileNames)
066    // NOTE: For the top-level main 'Stats' instance, this will remain null
067
068    public final ReadOnlyMap<String, String> packageTagsMap;
069
070
071    // Keeps a count of the use of all "Package-Local Embed-Tags"
072    // NOTE: For the top-level main 'Stats' instance, this will remain null
073
074    public final ReadOnlyMap<String, Integer> packageTagsCount;
075
076
077    // ********************************************************************************************
078    // ********************************************************************************************
079    // Stats Fields: BASIC
080    // ********************************************************************************************
081    // ********************************************************************************************
082
083
084    /** Maintains A count of the total number of lines of {@code '.java'} files. */
085    public final int numLines;
086
087    /** Maintains A count of the total number of bytes of {@code '.java'} files. */
088    public final int numBytes;
089
090    /** Maintains A count of the total number of HiLited HTML {@code <DIV>} Elements. */
091    public final int numHiLitedDivs;
092
093
094    // ********************************************************************************************
095    // ********************************************************************************************
096    // Stats: Entity (METHOD, FIELD, CONSTRUCTOR, ANNOTATION_ELEM, ENUM_CONSTANT)
097    // ********************************************************************************************
098    // ********************************************************************************************
099
100
101    /** Maintains A count of the total number of methods found during the upgrade. */
102    public final int numMethods;
103
104    /** Maintains A count of the total number of constructors found during the upgrade. */
105    public final int numConstructors;
106
107    /** Maintains A count of the total number of fields found during the upgrade. */
108    public final int numFields;
109
110    /** Maintains A count of the total number of annotation-elements found during the upgrade. */
111    public final int numAnnotationElems;
112
113    /** Maintains A count of the total number of enum-constants found during the upgrade. */
114    public final int numEnumConstants;
115
116
117    // ********************************************************************************************
118    // ********************************************************************************************
119    // Stats: HILITED-Entity (METHOD, FIELD, CONSTRUCTOR, ANNOTATION_ELEM, ENUM_CONSTANT)
120    // ********************************************************************************************
121    // ********************************************************************************************
122
123
124    /** Maintains A count of the total number of method bodies hilited by the upgrader. */
125    public final int numHiLitedMethods;
126
127    /** Maintains A count of the total number of constructor bodies hilited by the upgrader. */
128    public final int numHiLitedConstructors;
129
130    /** Maintains A count of the total number of field declarations hilited by the upgrader. */
131    public final int numHiLitedFields;
132
133    /** A count of the total number of annotation-element declarations hilited by the upgrader. */
134    public final int numHiLitedAnnotationElems;
135
136    /** A count of the total number of enumeration-constant declarations hilited by the upgrader.*/
137    public final int numHiLitedEnumConstants;
138
139
140    // ********************************************************************************************
141    // ********************************************************************************************
142    // Stats: DOCUMENTED-Entity (METHOD, FIELD, CONSTRUCTOR, ANNOTATION_ELEM, ENUM_CONSTANT)
143    // ********************************************************************************************
144    // ********************************************************************************************
145
146
147    /** Maintains A count of the total number of methods that were documented by Java Doc. */
148    public final int numDocumentedMethods;
149
150    /** Maintains A count of the total number of constructors that were documented by Java Doc. */
151    public final int numDocumentedConstructors;
152
153    /** Maintains A count of the total number of fields that were documented by Java Doc. */
154    public final int numDocumentedFields;
155
156    /** A count of the total number of annotation-elements that were documented by Java Doc. */
157    public final int numDocumentedAnnotationElems;
158
159    /** A count of the total number of annotation-elements that were documented by Java Doc. */
160    public final int numDocumentedEnumConstants;
161
162
163    // ********************************************************************************************
164    // ********************************************************************************************
165    // Stats: STATIC-Entity (METHOD, FIELD)
166    // ********************************************************************************************
167    // ********************************************************************************************
168
169
170    /** Maintains A count of the total number of {@code static} methods found during the upgrade. */
171    public final int numStaticMethods;
172
173    /** Maintains A count of the total number of {@code static} fields found during the upgrade. */
174    public final int numStaticFields;
175
176
177    // ********************************************************************************************
178    // ********************************************************************************************
179    // Stats: FINAL-Entity (METHOD, FIELD, CONSTRUCTOR)
180    // ********************************************************************************************
181    // ********************************************************************************************
182
183
184    /** Maintains A count of the total number of {@code final} methods found by the upgrade. */
185    public final int numFinalMethods;
186
187    /** Maintains A count of the total number of {@code final} constructors found by the upgrader. */
188    public final int numFinalConstructors;
189
190    /** Maintains A count of the total number of {@code final} fields found by the upgrader. */
191    public final int numFinalFields;
192
193
194    // ********************************************************************************************
195    // ********************************************************************************************
196    // Stats: PUBLIC-Entity (METHOD, FIELD, CONSTRUCTOR)
197    // ********************************************************************************************
198    // ********************************************************************************************
199
200
201    /** Maintains A count of the total number of {@code public} methods found by the upgrader. */
202    public final int numPublicMethods;
203
204    /** Maintains A count of the total number of {@code public} constructors found by the upgrader.*/
205    public final int numPublicConstructors;
206
207    /** Maintains A count of the total number of {@code public} fields found by the upgrader. */
208    public final int numPublicFields;
209
210
211    // ********************************************************************************************
212    // ********************************************************************************************
213    // Stats: PROTECTED-Entity (METHOD, FIELD, CONSTRUCTOR)
214    // ********************************************************************************************
215    // ********************************************************************************************
216
217
218    /** Maintains The total number of {@code protected} methods found during the upgrade. */
219    public final int numProtectedMethods;
220
221    /** Maintains The total number of {@code protected} constructors found during the upgrade. */
222    public final int numProtectedConstructors;
223
224    /** Maintains The total number of {@code protected} fields found during the upgrade. */
225    public final int numProtectedFields;
226
227
228    // ********************************************************************************************
229    // ********************************************************************************************
230    // Stats: PRIVATE-Entity (METHOD, FIELD, CONSTRUCTOR)
231    // ********************************************************************************************
232    // ********************************************************************************************
233
234
235    /** Maintains The total number of {@code private} methods found during the upgrade. */
236    public final int numPrivateMethods;
237
238    /** Maintains The total number of {@code private} constructors found during the upgrade. */
239    public final int numPrivateConstructors;
240
241    /** Maintains The total number of {@code private} fields found during the upgrade. */
242    public final int numPrivateFields;
243
244
245    // ********************************************************************************************
246    // ********************************************************************************************
247    // Stats: OTHER-Entity (FIELD only)
248    // ********************************************************************************************
249    // ********************************************************************************************
250
251
252    /** Maintains A count of the total number of {@code transient} fields found during the upgrade.*/
253    public final int numTransientFields;
254
255    /** Maintains A count of the total number of {@code volatile} fields found during the upgrade. */
256    public final int numVolatileFields;
257
258
259    // ********************************************************************************************
260    // ********************************************************************************************
261    // Constructor
262    // ********************************************************************************************
263    // ********************************************************************************************
264
265
266    public Stats(final StatsInternal si)
267    {
268        // null for the "Top-Level" instance.  For 'Stats' instances that are used to represent
269        // Java-Packages, the 'packageName' field for a 'StatsInternal' instance is, literally, 
270        // just the Name-as-a-String of the Java-Package being described.
271
272        this.packageName = si.packageName;
273
274
275        // This is never null - even for Package-Level instance.  Package-Level instances are 
276        // actually instantiated, internally, in class 'StatsInternal', and they utilize a private
277        // constructor.  The Private-Constructor uses the Top-Level 'StatsInternal' instance to 
278        // make sure that the "globalTagsMap" reference from the 'Top-Level-Instance' is properly
279        // passed to all of the Package-Level (children) instances within the container.
280        // 
281        // Note: Again, the "container" is just the lone Top-Level-Instance.  The 'Stats' and the
282        //       'StatsInternal' data-structures are mirrors, and neither of them are *TREES* of
283        //       Java-Package 'Stats' (Statistics) instances, instead they have a single, internal,
284        //       list that contains all of the 'Stats' and 'StatsInternal' instances which are
285        //       associated with a User's Packages.
286        // 
287        // Also: This 'Map' is nothing but the POJO-Version of the users
288        // 'external-html-ids.properties' file for the "Global <EMBED>-Tags"
289    
290        this.globalTagsMap  = si.globalTagsMap;
291
292        // A little bit of effciency
293        this.globalTagsCount = (si.globalTagsCount.size() > 0)
294            ? new ReadOnlyTreeMap<>(si.globalTagsCount)
295            : ReadOnlyTreeMap.emptyROTM();
296
297        this.packageTagsMap = si.packageTagsMap;
298
299        // This is null for the "Global, Top-Level" Stats-Instance
300        this.packageTagsCount = (si.packageTagsCount == null)
301            ? null
302            : (si.packageTagsCount.size() > 0)
303                ? new ReadOnlyTreeMap<>(si.packageTagsCount)
304                : ReadOnlyTreeMap.emptyROTM();
305
306        // This Field shall contain a map of "Package-Name" to "Package Stats-Instances"
307        if (si.packageStatsMap == null) this.packageStatsMap = null;
308 
309        else
310        {
311            final ROTreeMapBuilder<String, Stats> rotmb = new ROTreeMapBuilder<>();
312
313            // public final Map<String, Stats> packageStatsMap;
314            for (final String key : si.packageStatsMap.keySet())
315            {
316                final StatsInternal siInner     = si.packageStatsMap.get(key);
317                final Stats         statsInner  = new Stats(siInner);
318
319                rotmb.put(key, statsInner);
320            }
321
322            this.packageStatsMap = rotmb.build();
323        }
324
325        this.numLines                       = si.numLines();
326        this.numBytes                       = si.numBytes();
327        this.numHiLitedDivs                 = si.numHiLitedDivs();
328    
329        this.numMethods                     = si.numMethods();
330        this.numConstructors                = si.numConstructors();
331        this.numFields                      = si.numFields();
332        this.numAnnotationElems             = si.numAnnotationElems();
333        this.numEnumConstants               = si.numEnumConstants();
334    
335        this.numHiLitedMethods              = si.numHiLitedMethods();
336        this.numHiLitedConstructors         = si.numHiLitedConstructors();
337        this.numHiLitedFields               = si.numHiLitedFields();
338        this.numHiLitedAnnotationElems      = si.numHiLitedAnnotationElems();
339        this.numHiLitedEnumConstants        = si.numHiLitedEnumConstants();
340    
341        this.numDocumentedMethods           = si.numDocumentedMethods();
342        this.numDocumentedConstructors      = si.numDocumentedConstructors();
343        this.numDocumentedFields            = si.numDocumentedFields();
344        this.numDocumentedAnnotationElems   = si.numDocumentedAnnotationElems();
345        this.numDocumentedEnumConstants     = si.numDocumentedEnumConstants();
346    
347        this.numStaticMethods               = si.numStaticMethods();
348        this.numStaticFields                = si.numStaticFields();
349
350        this.numFinalMethods                = si.numFinalMethods();
351        this.numFinalConstructors           = si.numFinalConstructors();
352        this.numFinalFields                 = si.numFinalFields();
353    
354        this.numPublicMethods               = si.numPublicMethods();
355        this.numPublicConstructors          = si.numPublicConstructors();
356        this.numPublicFields                = si.numPublicFields();
357
358        this.numProtectedMethods            = si.numProtectedMethods();
359        this.numProtectedConstructors       = si.numProtectedConstructors();
360        this.numProtectedFields             = si.numProtectedFields();
361    
362        this.numPrivateMethods              = si.numPrivateMethods();
363        this.numPrivateConstructors         = si.numPrivateConstructors();
364        this.numPrivateFields               = si.numPrivateFields();
365
366        this.numTransientFields             = si.numTransientFields();
367        this.numVolatileFields              = si.numVolatileFields();
368    }
369
370
371    // ********************************************************************************************
372    // ********************************************************************************************
373    // To String
374    // ********************************************************************************************
375    // ********************************************************************************************
376
377
378    /**
379     * Generates a {@code String} that enapsulates all of the counters / running-totals inside
380     * this data statistic class.
381     * 
382     * @return A {@code String} representation of this class.  Only includes statistics about
383     * use of methods, constructors, fields etc...  <B>DOES NOT INCLUDE</B> statistics regarding
384     * the use of the {@code <EMBED CLASS='external-html' ...>} tags.
385     */
386    public String toString()
387    { return Torello.JDUInternal.Features.STATS.API_Stats.toString(this); }
388}