changeset 1020:af27f02e778a

7901070: Clean up Map usages
author shade
date Fri, 24 Oct 2014 14:56:55 +0400
parents 1a4b13657050
children 07488524786d
files jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodGroup.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/results/format/JSONResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/results/format/TextResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkListEntry.java jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/runner/WorkloadParams.java jmh-core/src/main/java/org/openjdk/jmh/util/HashMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/HashsetMultimap.java jmh-core/src/main/java/org/openjdk/jmh/util/TreeMultimap.java
diffstat 12 files changed, 37 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core-ct/src/test/java/org/openjdk/jmh/ct/CompileTest.java	Fri Oct 24 14:56:55 2014 +0400
@@ -101,8 +101,10 @@
         }
 
         Collection<JavaSourceFromString> sources = new ArrayList<JavaSourceFromString>();
-        for (String name : destination.classBodies.keySet()) {
-            sources.add(new JavaSourceFromString(name, destination.classBodies.get(name).toString()));
+        for (Map.Entry<String, StringWriter> e : destination.classBodies.entrySet()) {
+            String name = e.getKey();
+            String body = e.getValue().toString();
+            sources.add(new JavaSourceFromString(name, body));
         }
 
         JavaCompiler.CompilationTask task = javac.getTask(null, fm, diagnostics, null, null, sources);
--- a/jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodGroup.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/generators/core/MethodGroup.java	Fri Oct 24 14:56:55 2014 +0400
@@ -268,8 +268,9 @@
     public Optional<Map<String, String[]>> getParams() {
         Map<String, String[]> map = new TreeMap<String, String[]>();
 
-        for (String key : params.keySet()) {
-            String[] values = params.get(key);
+        for (Map.Entry<String, String[]> e : params.entrySet()) {
+            String key = e.getKey();
+            String[] values = e.getValue();
             if (values.length == 1 && values[0].equalsIgnoreCase(Param.BLANK_ARGS)) {
                 map.put(key, new String[0]);
             } else {
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Fri Oct 24 14:56:55 2014 +0400
@@ -496,8 +496,8 @@
 
         {
             int sum = 0;
-            for (String ev : events.totalCounts.keySet()) {
-                sum += events.totalCounts.get(ev);
+            for (Long v : events.totalCounts.values()) {
+                sum += v;
             }
 
             if (sum < 1000) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/format/JSONResultFormat.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/format/JSONResultFormat.java	Fri Oct 24 14:56:55 2014 +0400
@@ -35,6 +35,7 @@
 import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Map;
 
 class JSONResultFormat implements ResultFormat {
 
@@ -100,8 +101,9 @@
             }
 
             Collection<String> secondaries = new ArrayList<String>();
-            for (String secondaryName : runResult.getSecondaryResults().keySet()) {
-                Result result = runResult.getSecondaryResults().get(secondaryName);
+            for (Map.Entry<String, Result> e : runResult.getSecondaryResults().entrySet()) {
+                String secondaryName = e.getKey();
+                Result result = e.getValue();
 
                 StringBuilder sb = new StringBuilder();
                 sb.append("\"").append(secondaryName).append("\" : {");
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/format/TextResultFormat.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/format/TextResultFormat.java	Fri Oct 24 14:56:55 2014 +0400
@@ -96,8 +96,7 @@
             scoreErrLen = Math.max(scoreErrLen, String.format("%.3f", primRes.getScoreError()).length());
             unitLen     = Math.max(unitLen,     primRes.getScoreUnit().length());
 
-            for (String label : res.getSecondaryResults().keySet()) {
-                Result subRes = res.getSecondaryResults().get(label);
+            for (Result subRes : res.getSecondaryResults().values()) {
                 samplesLen  = Math.max(samplesLen,  String.format("%d",   subRes.getSampleCount()).length());
                 scoreLen    = Math.max(scoreLen,    String.format("%.3f", subRes.getScore()).length());
                 scoreErrLen = Math.max(scoreErrLen, String.format("%.3f", subRes.getScoreError()).length());
@@ -143,8 +142,9 @@
                 out.println();
             }
 
-            for (String label : res.getSecondaryResults().keySet()) {
-                Result subRes = res.getSecondaryResults().get(label);
+            for (Map.Entry<String, Result> e : res.getSecondaryResults().entrySet()) {
+                String label = e.getKey();
+                Result subRes = e.getValue();
 
                 out.print(String.format("%-" + nameLen + "s",
                         benchPrefixes.get(res.getParams().getBenchmark() + ":" + label)));
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkListEntry.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BenchmarkListEntry.java	Fri Oct 24 14:56:55 2014 +0400
@@ -378,13 +378,13 @@
         @Override
         public String valueOf(Map<String, String[]> src) {
             StringBuilder sb = new StringBuilder();
-            for (String s : src.keySet()) {
-                sb.append(s);
+            for (Map.Entry<String, String[]> e : src.entrySet()) {
+                sb.append(e.getKey());
                 sb.append("===SEP-K===");
-                if (src.get(s).length == 0) {
+                if (e.getValue().length == 0) {
                     sb.append("===EMPTY===");
                 } else {
-                    for (String v : src.get(s)) {
+                    for (String v : e.getValue()) {
                         sb.append(v);
                         sb.append("===SEP-V===");
                     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/LoopBenchmarkHandler.java	Fri Oct 24 14:56:55 2014 +0400
@@ -131,8 +131,9 @@
         // The abrupt exception in any worker will float up here.
         int expected = numThreads;
         while (expected > 0) {
-            for (BenchmarkTask task : results.keySet()) {
-                Future<Collection<? extends Result>> fr = results.get(task);
+            for (Map.Entry<BenchmarkTask, Future<Collection<? extends Result>>> re : results.entrySet()) {
+                BenchmarkTask task = re.getKey();
+                Future<Collection<? extends Result>> fr = re.getValue();
                 try {
                     long waitFor = Math.max(TimeUnit.MILLISECONDS.toNanos(100), waitDeadline - System.nanoTime());
                     fr.get(waitFor, TimeUnit.NANOSECONDS);
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri Oct 24 14:56:55 2014 +0400
@@ -473,8 +473,10 @@
     private List<WorkloadParams> explodeAllParams(BenchmarkListEntry br) throws RunnerException {
         Map<String, String[]> benchParams = br.getParams().orElse(Collections.<String, String[]>emptyMap());
         List<WorkloadParams> ps = new ArrayList<WorkloadParams>();
-        for (String k : benchParams.keySet()) {
-            Collection<String> values = options.getParameter(k).orElse(Arrays.asList(benchParams.get(k)));
+        for (Map.Entry<String, String[]> e : benchParams.entrySet()) {
+            String k = e.getKey();
+            String[] vals = e.getValue();
+            Collection<String> values = options.getParameter(k).orElse(Arrays.asList(vals));
             if (values.isEmpty()) {
                 throw new RunnerException("Benchmark \"" + br.getUsername() +
                         "\" defines the parameter \"" + k + "\", but no default values.\n" +
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/WorkloadParams.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/WorkloadParams.java	Fri Oct 24 14:56:55 2014 +0400
@@ -26,6 +26,7 @@
 
 import java.io.Serializable;
 import java.util.Collection;
+import java.util.Map;
 import java.util.SortedMap;
 import java.util.TreeMap;
 
@@ -49,8 +50,8 @@
             throw new IllegalStateException("Comparing actual params with different key sets.");
         }
 
-        for (String key : params.keySet()) {
-            int cr = params.get(key).compareTo(o.params.get(key));
+        for (Map.Entry<String, Value> e : params.entrySet()) {
+            int cr = e.getValue().compareTo(o.params.get(e.getKey()));
             if (cr != 0) {
                 return cr;
             }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/HashMultimap.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/HashMultimap.java	Fri Oct 24 14:56:55 2014 +0400
@@ -84,8 +84,8 @@
     @Override
     public Collection<V> values() {
         Collection<V> result = new ArrayList<V>();
-        for (K key : map.keySet()) {
-            result.addAll(map.get(key));
+        for (Collection<V> vs : map.values()) {
+            result.addAll(vs);
         }
         return result;
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/HashsetMultimap.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/HashsetMultimap.java	Fri Oct 24 14:56:55 2014 +0400
@@ -85,8 +85,8 @@
     @Override
     public Collection<V> values() {
         Collection<V> result = new ArrayList<V>();
-        for (K key : map.keySet()) {
-            result.addAll(map.get(key));
+        for (Collection<V> vs : map.values()) {
+            result.addAll(vs);
         }
         return result;
     }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/TreeMultimap.java	Fri Oct 10 18:58:28 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/TreeMultimap.java	Fri Oct 24 14:56:55 2014 +0400
@@ -84,8 +84,8 @@
     @Override
     public Collection<V> values() {
         Collection<V> result = new ArrayList<V>();
-        for (K key : map.keySet()) {
-            result.addAll(map.get(key));
+        for (Collection<V> vs : map.values()) {
+            result.addAll(vs);
         }
         return result;
     }