linux.ui: simplify optimizer with multiset
authorMatthew Khouzam <matthew.khouzam@ericsson.com>
Tue, 26 Jul 2016 03:00:33 +0000 (23:00 -0400)
committerMatthew Khouzam <matthew.khouzam@ericsson.com>
Wed, 3 Aug 2016 22:31:48 +0000 (18:31 -0400)
Replace the patterns of getx, put(x+1) with a multiset.
Replace large stream operation with simple built-in function.

Change-Id: I2697de79929ffcc4998cac8ed220c549fc577fbf
Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/77874
Reviewed-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Tested-by: Jean-Christian Kouame <jean-christian.kouame@ericsson.com>
Reviewed-by: Hudson CI
analysis/org.eclipse.tracecompass.analysis.os.linux.ui/src/org/eclipse/tracecompass/internal/analysis/os/linux/ui/views/controlflow/ControlFlowView.java

index e0df2aff7da20ddbf7aa2262699a221c5cedd7e8..fe8535b0752ef1e103c2c754c6731577d847ec96 100644 (file)
@@ -87,7 +87,10 @@ import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.Resolution;
 import org.eclipse.tracecompass.tmf.ui.widgets.timegraph.widgets.Utils.TimeFormat;
 
+import com.google.common.collect.HashMultiset;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Multiset;
+import com.google.common.collect.Multisets;
 
 /**
  * The Control Flow view main object
@@ -517,7 +520,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
              * (Pair<Integer, Integer>). For constructing the Pair, we always
              * put the smallest tid first
              */
-            Map<Pair<Integer, Integer>, Integer> transitions = new HashMap<>();
+            Multiset<Pair<Integer, Integer>> transitions = HashMultiset.<Pair<Integer,Integer>>create();
 
             /*
              * We iterate in arrows to count the number of transitions between
@@ -533,8 +536,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
                 int toTid = ((ControlFlowEntry) to).getThreadId();
                 if (fromTid != toTid) {
                     Pair<Integer, Integer> key = new Pair<>(Math.min(fromTid, toTid), Math.max(fromTid, toTid));
-                    Integer count = transitions.getOrDefault(key, 0);
-                    transitions.put(key, count + 1);
+                    transitions.add(key);
                 }
             }
 
@@ -543,7 +545,7 @@ public class ControlFlowView extends AbstractStateSystemTimeGraphView {
              * step is to sort every pair according to its count in decreasing
              * order
              */
-            List<Pair<Integer, Integer>> sortedTransitionsByCount = transitions.entrySet().stream().sorted(Map.Entry.<Pair<Integer, Integer>, Integer> comparingByValue().reversed()).map(Map.Entry::getKey).collect(Collectors.toList());
+            List<Pair<Integer, Integer>> sortedTransitionsByCount = Multisets.copyHighestCountFirst(transitions).asList();
 
             /*
              * Next, we find the order in which we want to display our threads.
This page took 0.026587 seconds and 5 git commands to generate.