changeset 1350:5bacc2ced653

7901790: Revisit result aggregation checks: labels, roles, units
author shade
date Thu, 15 Sep 2016 12:48:53 +0200
parents c4aaa7a112b6
children 8c20adb08b2d
files jmh-core/src/main/java/org/openjdk/jmh/results/AggregatorUtils.java jmh-core/src/main/java/org/openjdk/jmh/results/SampleTimeResult.java
diffstat 2 files changed, 17 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/AggregatorUtils.java	Thu Sep 15 11:53:02 2016 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/AggregatorUtils.java	Thu Sep 15 12:48:53 2016 +0200
@@ -32,54 +32,49 @@
         // prevent instantation
     }
 
-    public static ResultRole aggregateRoles(Collection<? extends Result> results) {
+    static ResultRole aggregateRoles(Collection<? extends Result> results) {
         ResultRole result = null;
         for (Result r : results) {
             if (result == null) {
                 result = r.role;
-            } else {
-                if (result != r.role) {
-                    throw new IllegalStateException("Combining the results with different roles");
-                }
+            } else if (result != r.role) {
+                throw new IllegalStateException("Combining the results with different roles");
             }
         }
         return result;
     }
 
-    public static String aggregateUnits(Collection<? extends Result> results) {
+    static String aggregateUnits(Collection<? extends Result> results) {
         String result = null;
         for (Result r : results) {
             if (result == null) {
                 result = r.unit;
-            } else {
-                if (!result.equals(r.unit)) {
-                    throw new IllegalStateException("Combining the results with different units");
-                }
+            } else if (!result.equals(r.unit)) {
+                throw new IllegalStateException("Combining the results with different units");
             }
         }
         return result;
     }
 
-    public static String aggregateLabels(Collection<? extends Result> results) {
+    static String aggregateLabels(Collection<? extends Result> results) {
         String result = null;
         for (Result r : results) {
-            // pick the first one
             if (result == null) {
                 result = r.label;
+            } else if (!result.equals(r.label)) {
+                throw new IllegalStateException("Combining the results with different labels");
             }
         }
         return result;
     }
 
-    public static AggregationPolicy aggregatePolicies(Collection<? extends Result> results) {
+    static AggregationPolicy aggregatePolicies(Collection<? extends Result> results) {
         AggregationPolicy result = null;
         for (Result r : results) {
             if (result == null) {
                 result = r.policy;
-            } else {
-                if (!result.equals(r.policy)) {
-                    throw new IllegalStateException("Combining the results with different aggregation policies");
-                }
+            } else if (!result.equals(r.policy)) {
+                throw new IllegalStateException("Combining the results with different aggregation policies");
             }
         }
         return result;
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/SampleTimeResult.java	Thu Sep 15 11:53:02 2016 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/SampleTimeResult.java	Thu Sep 15 12:48:53 2016 +0200
@@ -103,7 +103,11 @@
             TimeUnit tu = null;
             for (SampleTimeResult r : results) {
                 buffer.addAll(r.buffer);
-                tu = r.outputTimeUnit;
+                if (tu == null) {
+                    tu = r.outputTimeUnit;
+                } else if (!tu.equals(r.outputTimeUnit)){
+                    throw new IllegalStateException("Combining the results with different timeunits");
+                }
             }
             return new SampleTimeResult(
                     AggregatorUtils.aggregateRoles(results),