diff --git a/src/main/java/br/ufrgs/inf/prosoft/tfcache/metadata/Method.java b/src/main/java/br/ufrgs/inf/prosoft/tfcache/metadata/Method.java
index 91bcc9f..f30b16e 100755
--- a/src/main/java/br/ufrgs/inf/prosoft/tfcache/metadata/Method.java
+++ b/src/main/java/br/ufrgs/inf/prosoft/tfcache/metadata/Method.java
@@ -9,12 +9,9 @@ import br.ufrgs.inf.prosoft.tfcache.Metrics;
import br.ufrgs.inf.prosoft.tfcache.Simulator;
import br.ufrgs.inf.prosoft.tfcache.StorageManager;
import br.ufrgs.inf.prosoft.tfcache.configuration.Configuration;
+
import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.logging.Level;
@@ -23,7 +20,6 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
- *
* @author romulo
*/
public class Method {
@@ -49,6 +45,25 @@ public class Method {
this.occurrences = occurrences;
}
+ public static Map<String, List<Occurrence>> groupByInput(List<Occurrence> occurrences) {
+ if (occurrences == null) {
+ throw new RuntimeException("Occurrences cannot be null");
+ }
+ Map<String, List<Occurrence>> inputHasOccurrences = new ConcurrentHashMap<>();
+ occurrences.stream().forEach(occurrence -> {
+ String parameters = occurrence.getParametersSerialised();
+
+ inputHasOccurrences.compute(parameters, (key, oldValue) -> {
+ if (oldValue == null) {
+ oldValue = new ArrayList<>();
+ }
+ oldValue.add(occurrence);
+ return oldValue;
+ });
+ });
+ return inputHasOccurrences;
+ }
+
public String getName() {
return name;
}
@@ -57,6 +72,13 @@ 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();
@@ -98,25 +120,6 @@ public class Method {
.collect(Collectors.toList());
}
- public static Map<String, List<Occurrence>> groupByInput(List<Occurrence> occurrences) {
- if (occurrences == null) {
- throw new RuntimeException("Occurrences cannot be null");
- }
- Map<String, List<Occurrence>> inputHasOccurrences = new ConcurrentHashMap<>();
- occurrences.stream().forEach(occurrence -> {
- String parameters = occurrence.getParametersSerialised();
-
- inputHasOccurrences.compute(parameters, (key, oldValue) -> {
- if (oldValue == null) {
- oldValue = new ArrayList<>();
- }
- oldValue.add(occurrence);
- return oldValue;
- });
- });
- return inputHasOccurrences;
- }
-
public void removeChangeableInputs() {
if (this.countChangeableGroups != null) {
throw new RuntimeException("Changeable already filtered");
@@ -188,7 +191,7 @@ public class Method {
if (this.occurrences.size() < 2) {
return;
}
- this.occurrences.sort((occurrence1, occurrence2) -> Long.compare(occurrence1.getStartTime(), occurrence2.getStartTime()));
+ this.occurrences.sort(Comparator.comparingLong(Occurrence::getStartTime));
Simulator.simulate(this.occurrences, this.bestMetrics);
}