Author: erans
Date: Wed Nov 14 22:55:07 2012
New Revision: 1409509

URL: http://svn.apache.org/viewvc?rev=1409509&view=rev
Log:
Replaced calls to deprecated methods in "ResizeableDoubleArray" (see
MATH-894). Created subclass of "ResizeableDoubleArray" in order to
access to the object's internal array.

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java?rev=1409509&r1=1409508&r2=1409509&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math3/stat/descriptive/DescriptiveStatistics.java
 Wed Nov 14 22:55:07 2012
@@ -79,7 +79,7 @@ public class DescriptiveStatistics imple
     /**
      *  Stored data values
      */
-    private ResizableDoubleArray eDA = new ResizableDoubleArray();
+    private StatArray eDA = new StatArray();
 
     /** Mean statistic implementation - can be reset by setter. */
     private UnivariateStatistic meanImpl = new Mean();
@@ -138,7 +138,7 @@ public class DescriptiveStatistics imple
      */
     public DescriptiveStatistics(double[] initialDoubleArray) {
         if (initialDoubleArray != null) {
-            eDA = new ResizableDoubleArray(initialDoubleArray);
+            eDA = new StatArray(initialDoubleArray);
         }
     }
 
@@ -484,7 +484,7 @@ public class DescriptiveStatistics imple
      */
     public double apply(UnivariateStatistic stat) {
         // No try-catch or advertised exception here because arguments are 
guaranteed valid
-        return stat.evaluate(eDA.getInternalValues(), eDA.start(), 
eDA.getNumElements());
+        return eDA.compute(stat);
     }
 
     // Implementation getters and setter
@@ -762,4 +762,55 @@ public class DescriptiveStatistics imple
         dest.skewnessImpl = source.skewnessImpl;
         dest.percentileImpl = source.percentileImpl;
     }
+
+    /**
+     * Provides a method to compute a statistics on the contents of the
+     * array.
+     */
+    private static class StatArray extends ResizableDoubleArray {
+        /** Default constructor. */
+        public StatArray() {}
+
+        /**
+         * Builds an instance with the same contents as the given array.
+         *
+         * @param initialArray Data.
+         */
+        public StatArray(double[] initialArray) {
+            super(initialArray);
+        }
+
+        /**
+         * Builds a copy of the given instance.
+         *
+         * @param other Array.
+         * @throws NullArgumentException if the argument is {@code null}.
+         */
+        public StatArray(StatArray other)
+            throws NullArgumentException {
+            super(other);
+        }
+
+        /**
+         * Computes the given statistics from the contents of this array.
+         *
+         * @param stat Statistics.
+         * @return the result of evaluating the statistics on the current
+         * contents of this array.
+         */
+        public double compute(UnivariateStatistic stat) {
+            return stat.evaluate(getArrayRef(),
+                                 getStartIndex(),
+                                 getNumElements());
+        }
+
+        /**
+         * Creates a copy of this instance.
+         *
+         * @return a copy of this instance.
+         */
+        public StatArray copy() {
+            return new StatArray(this);
+        }
+    }
 }


Reply via email to