You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ps...@apache.org on 2011/01/02 02:46:23 UTC
svn commit: r1054342 - in /commons/proper/math:
branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
trunk/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
Author: psteitz
Date: Sun Jan 2 01:46:22 2011
New Revision: 1054342
URL: http://svn.apache.org/viewvc?rev=1054342&view=rev
Log:
Modified constructor added in the fix for JIRA: MATH-384 to copy, rather than reference the input array.
Modified:
commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
Modified: commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
URL: http://svn.apache.org/viewvc/commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java?rev=1054342&r1=1054341&r2=1054342&view=diff
==============================================================================
--- commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java (original)
+++ commons/proper/math/branches/MATH_2_X/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java Sun Jan 2 01:46:22 2011
@@ -165,6 +165,7 @@ public class ResizableDoubleArray implem
* initial capacity and numElements corresponding to the size of
* the supplied double[] array. If the supplied array is null, a
* new empty array with the default initial capacity will be created.
+ * The input array is copied, not referenced.
* Other properties take default values:
* <ul>
* <li><code>initialCapacity = 16</code></li>
@@ -174,12 +175,14 @@ public class ResizableDoubleArray implem
* </ul>
*
* @param initialArray initial array
+ * @since 2.2
*/
public ResizableDoubleArray(double[] initialArray) {
if (initialArray == null) {
- internalArray = new double[initialCapacity];
+ this.internalArray = new double[initialCapacity];
} else {
- internalArray = initialArray;
+ this.internalArray = new double[initialArray.length];
+ System.arraycopy(initialArray, 0, this.internalArray, 0, initialArray.length);
initialCapacity = initialArray.length;
numElements = initialArray.length;
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java?rev=1054342&r1=1054341&r2=1054342&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/ResizableDoubleArray.java Sun Jan 2 01:46:22 2011
@@ -161,10 +161,11 @@ public class ResizableDoubleArray implem
}
/**
- * Create a ResizableArray from an existing double[] with the
- * initial capacity and numElements corresponding to the size of
- * the supplied double[] array. If the supplied array is null, a
- * new empty array with the default initial capacity will be created.
+ * Create a ResizableArray from an existing double[] with the
+ * initial capacity and numElements corresponding to the size of
+ * the supplied double[] array. If the supplied array is null, a
+ * new empty array with the default initial capacity will be created.
+ * The input array is copied, not referenced.
* Other properties take default values:
* <ul>
* <li><code>initialCapacity = 16</code></li>
@@ -172,14 +173,16 @@ public class ResizableDoubleArray implem
* <li><code>expansionFactor = 2.5</code></li>
* <li><code>contractionFactor = 2.0</code></li>
* </ul>
- *
+ *
* @param initialArray initial array
+ * @since 2.2
*/
public ResizableDoubleArray(double[] initialArray) {
if (initialArray == null) {
- internalArray = new double[initialCapacity];
+ this.internalArray = new double[initialCapacity];
} else {
- internalArray = initialArray;
+ this.internalArray = new double[initialArray.length];
+ System.arraycopy(initialArray, 0, this.internalArray, 0, initialArray.length);
initialCapacity = initialArray.length;
numElements = initialArray.length;
}