package com.datatheorem.android.trustkit.reporting;


import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

// Very basic implementation to rate-limit identical reports to once a day
class ReportRateLimiter {
    private static final long MAX_SECONDS_BETWEEN_CACHE_RESET = 3600*24;
    private static Set<List<Object>> reportsCache = new HashSet<>();
    protected static Date lastReportsCacheResetDate = new Date();

    public synchronized static boolean shouldRateLimit(final PinningFailureReport report) {
        // Reset the cache if it was created more than 24 hours ago
        Date currentDate = new Date();
        long secondsSinceLastReset =
                (currentDate.getTime() / 1000) - (lastReportsCacheResetDate.getTime() / 1000);
        if (secondsSinceLastReset > MAX_SECONDS_BETWEEN_CACHE_RESET) {
            reportsCache.clear();
            lastReportsCacheResetDate = currentDate;
        }

        // Check to see if an identical report is already in the cache
        List<Object> cacheEntry = new ArrayList<Object>() {{
            add(report.getNotedHostname());
            add(report.getServerHostname());
            add(report.getServerPort());
            add(report.getValidatedCertificateChainAsPem());
            add(report.getValidationResult());
        }};
        boolean shouldRateLimitReport = reportsCache.contains(cacheEntry);
        if (!shouldRateLimitReport){
            reportsCache.add(cacheEntry);
        }
        return shouldRateLimitReport;
    }
}

@@ -1103,33 +1103,32 @@
 ist%3C
-Object%3E() %7B%7B%0A            
+%3E();%0A        cacheEntry.
 add(
@@ -1155,36 +1155,43 @@
 ame());%0A        
-    
+cacheEntry.
 add(report.getSe
@@ -1207,36 +1207,43 @@
 ame());%0A        
-    
+cacheEntry.
 add(report.getSe
@@ -1255,36 +1255,43 @@
 ort());%0A        
-    
+cacheEntry.
 add(report.getVa
@@ -1331,20 +1331,27 @@
         
-  
-  
+cacheEntry.
 add(repo
@@ -1381,19 +1381,8 @@
 ));%0A
-        %7D%7D;
 %0A   

Tweak style