commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r348772 - in /jakarta/commons/proper/math/branches/MATH_1_1/src: java/org/apache/commons/math/random/EmpiricalDistributionImpl.java test/org/apache/commons/math/random/EmpiricalDistributionTest.java
Date Thu, 24 Nov 2005 17:26:40 GMT
Author: psteitz
Date: Thu Nov 24 09:26:34 2005
New Revision: 348772

URL: http://svn.apache.org/viewcvs?rev=348772&view=rev
Log:
Made sampleStats field private and changed getUpperBounds to return a fresh
copy in EmpiricalDistributionImpl.
BZ #36491
Reported by FindBugs

Modified:
    jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
    jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java?rev=348772&r1=348771&r2=348772&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java
Thu Nov 24 09:26:34 2005
@@ -65,7 +65,7 @@
     private ArrayList binStats = null;
 
     /** Sample statistics */
-    SummaryStatistics sampleStats = null;
+    private SummaryStatistics sampleStats = null;
 
     /** number of bins */
     private int binCount = 1000;
@@ -453,14 +453,18 @@
     }
 
     /**
-     * Returns the array of upper bounds for the bins.  Bins are: <br/>
+     * Returns (a fresh copy of) the array of upper bounds for the bins.
+       Bins are: <br/>
      * [min,upperBounds[0]],(upperBounds[0],upperBounds[1]],...,
      *  (upperBounds[binCount-1],max]
      * 
      * @return array of bin upper bounds
      */
     public double[] getUpperBounds() {
-        return upperBounds;
+        int len = upperBounds.length;
+        double[] out = new double[len];
+        System.arraycopy(upperBounds, 0, out, 0, len);
+        return out;
     }
 
     /**

Modified: jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java?rev=348772&r1=348771&r2=348772&view=diff
==============================================================================
--- jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java
(original)
+++ jakarta/commons/proper/math/branches/MATH_1_1/src/test/org/apache/commons/math/random/EmpiricalDistributionTest.java
Thu Nov 24 09:26:34 2005
@@ -115,6 +115,11 @@
         assertEquals
           (empiricalDistribution2.getSampleStats().getStandardDeviation(),
                 1.0173699343977738,10E-7);
+        
+        double[] bounds = empiricalDistribution2.getUpperBounds();
+        assertEquals(bounds.length, 100);
+        assertEquals(bounds[99], 1.0, 10e-12);
+          
     }
    
     /** 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message