commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r1038873 - in /commons/proper/math: branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/ branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/descriptive/ trunk/src/main/java/org/apache/commons/math/stat/descrip...
Date Wed, 24 Nov 2010 23:35:14 GMT
Author: psteitz
Date: Wed Nov 24 23:35:13 2010
New Revision: 1038873

URL: http://svn.apache.org/viewvc?rev=1038873&view=rev
Log:
Added toString() override to StatistictalSummaryValues.  JIRA: MATH-420.

Modified:
    commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
    commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java

Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java?rev=1038873&r1=1038872&r2=1038873&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
(original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
Wed Nov 24 23:35:13 2010
@@ -160,5 +160,27 @@ public class StatisticalSummaryValues im
         result = result * 31 + MathUtils.hash(getVariance());
         return result;
     }
+    
+    /**
+     * Generates a text report displaying values of statistics.
+     * Each statistic is displayed on a separate line.
+     *
+     * @return String with line feeds displaying statistics
+     */
+    @Override
+    public String toString() {
+        StringBuffer outBuffer = new StringBuffer();
+        String endl = "\n";
+        outBuffer.append("StatisticalSummaryValues:").append(endl);
+        outBuffer.append("n: ").append(getN()).append(endl);
+        outBuffer.append("min: ").append(getMin()).append(endl);
+        outBuffer.append("max: ").append(getMax()).append(endl);
+        outBuffer.append("mean: ").append(getMean()).append(endl);
+        outBuffer.append("std dev: ").append(getStandardDeviation())
+            .append(endl);
+        outBuffer.append("variance: ").append(getVariance()).append(endl);
+        outBuffer.append("sum: ").append(getSum()).append(endl);
+        return outBuffer.toString();
+    }
 
 }

Modified: commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java?rev=1038873&r1=1038872&r2=1038873&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
(original)
+++ commons/proper/math/branches/MATH_2_X/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
Wed Nov 24 23:35:13 2010
@@ -17,6 +17,8 @@
 package org.apache.commons.math.stat.descriptive;
 
 
+import java.util.Locale;
+
 import junit.framework.TestCase;
 
 import org.apache.commons.math.TestUtils;
@@ -65,4 +67,19 @@ public final class StatisticalSummaryVal
         TestUtils.assertEquals("min",s.getMin(),u.getMin(), 0);
         TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0);
     }
+    
+    public void testToString() {
+        StatisticalSummaryValues u  = new StatisticalSummaryValues(4.5, 16, 10, 5, 4, 45);
+        Locale d = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+        assertEquals("StatisticalSummaryValues:\n" +
+                     "n: 10\n" +
+                     "min: 4.0\n" +
+                     "max: 5.0\n" +
+                     "mean: 4.5\n" +
+                     "std dev: 4.0\n" +
+                     "variance: 16.0\n" +
+                     "sum: 45.0\n",  u.toString());
+        Locale.setDefault(d);
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java?rev=1038873&r1=1038872&r2=1038873&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
(original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValues.java
Wed Nov 24 23:35:13 2010
@@ -160,5 +160,27 @@ public class StatisticalSummaryValues im
         result = result * 31 + MathUtils.hash(getVariance());
         return result;
     }
+    
+    /**
+     * Generates a text report displaying values of statistics.
+     * Each statistic is displayed on a separate line.
+     *
+     * @return String with line feeds displaying statistics
+     */
+    @Override
+    public String toString() {
+        StringBuffer outBuffer = new StringBuffer();
+        String endl = "\n";
+        outBuffer.append("StatisticalSummaryValues:").append(endl);
+        outBuffer.append("n: ").append(getN()).append(endl);
+        outBuffer.append("min: ").append(getMin()).append(endl);
+        outBuffer.append("max: ").append(getMax()).append(endl);
+        outBuffer.append("mean: ").append(getMean()).append(endl);
+        outBuffer.append("std dev: ").append(getStandardDeviation())
+            .append(endl);
+        outBuffer.append("variance: ").append(getVariance()).append(endl);
+        outBuffer.append("sum: ").append(getSum()).append(endl);
+        return outBuffer.toString();
+    }
 
 }

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java?rev=1038873&r1=1038872&r2=1038873&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
(original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/stat/descriptive/StatisticalSummaryValuesTest.java
Wed Nov 24 23:35:13 2010
@@ -17,6 +17,8 @@
 package org.apache.commons.math.stat.descriptive;
 
 
+import java.util.Locale;
+
 import junit.framework.TestCase;
 
 import org.apache.commons.math.TestUtils;
@@ -65,4 +67,19 @@ public final class StatisticalSummaryVal
         TestUtils.assertEquals("min",s.getMin(),u.getMin(), 0);
         TestUtils.assertEquals("max",s.getMax(),u.getMax(), 0);
     }
+    
+    public void testToString() {
+        StatisticalSummaryValues u  = new StatisticalSummaryValues(4.5, 16, 10, 5, 4, 45);
+        Locale d = Locale.getDefault();
+        Locale.setDefault(Locale.US);
+        assertEquals("StatisticalSummaryValues:\n" +
+                     "n: 10\n" +
+                     "min: 4.0\n" +
+                     "max: 5.0\n" +
+                     "mean: 4.5\n" +
+                     "std dev: 4.0\n" +
+                     "variance: 16.0\n" +
+                     "sum: 45.0\n",  u.toString());
+        Locale.setDefault(d);
+    }
 }



Mime
View raw message