Claudenw commented on code in PR #233:
URL: https://github.com/apache/creadur-rat/pull/233#discussion_r1564518136


##########
apache-rat-core/src/main/java/org/apache/rat/report/claim/impl/ClaimAggregator.java:
##########
@@ -19,84 +19,80 @@
 
 package org.apache.rat.report.claim.impl;
 
+import java.util.Map;
+
+import org.apache.rat.api.Document;
 import org.apache.rat.api.MetaData;
 import org.apache.rat.api.RatException;
+import org.apache.rat.license.ILicense;
+import org.apache.rat.license.ILicenseFamily;
 import org.apache.rat.report.claim.ClaimStatistic;
-
-import java.util.HashMap;
-import java.util.Map;
-
+import org.apache.rat.report.claim.ClaimStatistic.Counter;
 
 /**
- * The aggregator is used to create a numerical statistic
- * of claims.
+ * The aggregator is used to create a numerical statistic of claims.
  */
 public class ClaimAggregator extends AbstractClaimReporter {
     private final ClaimStatistic statistic;
-    private final Map<String, Integer> numsByLicenseFamilyName = new 
HashMap<>();
-    private final Map<String, Integer> numsByLicenseFamilyCode = new 
HashMap<>();
-    private final Map<String, Integer> numsByFileType = new HashMap<>();
-    private int numApproved, numUnApproved, numGenerated, numUnknown;
 
-    public ClaimAggregator(ClaimStatistic pStatistic) {
-        statistic = pStatistic;
+    /**
+     * Constructor.
+     * @param statistic The statistic to store the statistics in.
+     */
+    public ClaimAggregator(ClaimStatistic statistic) {
+        this.statistic = statistic;
     }
-    
-    private void incMapValue(Map<String, Integer> pMap, String pKey) {
-        final Integer num = pMap.get(pKey);
-        final int newNum;
+
+    private <T> void incMapValue(Map<T, int[]> map, T key, int value) {
+        final int[] num = map.get(key);
+
         if (num == null) {
-            newNum = 1;
+            map.put(key, new int[] { value });
         } else {
-            newNum = num + 1;
+            num[0] += value;
         }
-        pMap.put(pKey, newNum);
     }
-    
+
     @Override
-    protected void handleDocumentCategoryClaim(String documentCategoryName) {
-        incMapValue(numsByFileType, documentCategoryName);
+    protected void handleDocumentCategoryClaim(Document.Type documentType) {
+        incMapValue(statistic.getDocumentCategoryMap(), documentType, 1);
     }
 
     @Override
-    protected void handleApprovedLicenseClaim(String licenseApproved) {
-        if (MetaData.RAT_APPROVED_LICENSE_VALUE_TRUE.equals(licenseApproved)) {
-            numApproved++;
+    protected void handleApprovedLicenseClaim(MetaData metadata) {
+        incValueMap(statistic.getCounterMap(), 
ClaimStatistic.Counter.Approved, metadata.approvedLicenses().count());
+        incValueMap(statistic.getCounterMap(), 
ClaimStatistic.Counter.Unapproved,
+                metadata.unapprovedLicenses().count());
+    }
+
+    private void incValueMap(Map<Counter, int[]> map, Counter key, long value) 
{

Review Comment:
   ClaimAggregator historically tracks integer values.  However we have several 
cases where we have streams that we call `count()` on.  They return longs.  We 
could cast them or convert them here.  I have changed this to be an `int` value 
and cast the stream counts.  I don't think that we will have more than MAX_INT 
defined licenses categories or licenses.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@creadur.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to