aplcachetf

readability and estimatedsavedtime

12/22/2020 12:47:36 AM

Details

diff --git a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java
index af242b8..cf32a1f 100644
--- a/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/aplcachetf/extension/metadata/Method.java
@@ -12,6 +12,7 @@ import br.ufrgs.inf.prosoft.tfcache.configuration.Configuration;
 import br.ufrgs.inf.prosoft.tfcache.metadata.Occurrence;
 import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
@@ -52,11 +53,18 @@ public class Method {
         return this.bestMetrics;
     }
 
+    public long getEstimatedSavedTime() {
+        if (getBestMetrics() != null) {
+            return getBestMetrics().getSavedTime();
+        }
+        return groupsOfOccurrences().map(group -> group.getSavedTime()).reduce(Long::sum).orElse(0L);
+    }
+    
     public BigDecimal getEstimatedSavedTimePerTimeInCache() {
         if (getBestMetrics() != null) {
             return getBestMetrics().getSavedTimePerTimeInCache();
         }
-        GroupOfOccurrences max = groupsOfOccurrences().max((group1, group2) -> group1.getSavedTimePerTimeInCache().compareTo(group2.getSavedTimePerTimeInCache())).get();
+        GroupOfOccurrences max = groupsOfOccurrences().max(Comparator.comparing(GroupOfOccurrences::getSavedTimePerTimeInCache)).get();
         return max.getSavedTimePerTimeInCache();
     }