changeset 221:78a68cce08d1

Double primitive specialization for Statistics.valueIterator().
author shade
date Mon, 04 Nov 2013 11:33:24 +0100
parents e56f65c57d68
children 31ede9a19bbd
files jmh-core/src/main/java/org/openjdk/jmh/util/internal/AbstractStatistics.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/DoubleIterator.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/ListStatistics.java jmh-core/src/main/java/org/openjdk/jmh/util/internal/MultisetStatistics.java
diffstat 4 files changed, 52 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/AbstractStatistics.java	Mon Nov 04 11:28:41 2013 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/AbstractStatistics.java	Mon Nov 04 11:33:24 2013 +0100
@@ -24,8 +24,6 @@
  */
 package org.openjdk.jmh.util.internal;
 
-import java.util.Iterator;
-
 public abstract class AbstractStatistics implements Statistics {
     private static final double[][] STUDENT_T = {
             {3.078, 6.314, 12.706, 31.821, 63.657, 318.313},
@@ -201,7 +199,7 @@
         if (getN() > 0) {
             double v = 0;
             double m = getMean();
-            for (Iterator<Double> it = valuesIterator(); it.hasNext(); ) {
+            for (DoubleIterator it = valuesIterator(); it.hasNext(); ) {
                 double d = it.next();
                 v += Math.pow(d - m, 2);
             }
@@ -211,5 +209,5 @@
         }
     }
 
-    protected abstract Iterator<Double> valuesIterator();
+    protected abstract DoubleIterator valuesIterator();
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/DoubleIterator.java	Mon Nov 04 11:33:24 2013 +0100
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.util.internal;
+
+public interface DoubleIterator {
+
+    boolean hasNext();
+
+    double next();
+
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/ListStatistics.java	Mon Nov 04 11:28:41 2013 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/ListStatistics.java	Mon Nov 04 11:33:24 2013 +0100
@@ -140,7 +140,19 @@
     }
 
     @Override
-    protected Iterator<Double> valuesIterator() {
-        return values.iterator();
+    protected DoubleIterator valuesIterator() {
+        return new DoubleIterator() {
+            private final Iterator<Double> backIterator = values.iterator();
+
+            @Override
+            public boolean hasNext() {
+                return backIterator.hasNext();
+            }
+
+            @Override
+            public double next() {
+                return backIterator.next();
+            }
+        };
     }
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/internal/MultisetStatistics.java	Mon Nov 04 11:28:41 2013 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/internal/MultisetStatistics.java	Mon Nov 04 11:33:24 2013 +0100
@@ -86,8 +86,8 @@
     }
 
     @Override
-    protected Iterator<Double> valuesIterator() {
-        return new Iterator<Double>() {
+    protected DoubleIterator valuesIterator() {
+        return new DoubleIterator() {
             private Iterator<Double> current = values.keys().iterator();
             private int count;
             private Double val;
@@ -106,7 +106,7 @@
             }
 
             @Override
-            public Double next() {
+            public double next() {
                 ensureNonEmpty();
                 if (count > 0) {
                     count--;
@@ -115,11 +115,6 @@
                     return Collections.<Double>emptyIterator().next();
                 }
             }
-
-            @Override
-            public void remove() {
-                throw new UnsupportedOperationException("Nope.");
-            }
         };
     }
 }