You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2010/10/01 15:09:25 UTC
svn commit: r1003526 - in
/commons/proper/math/trunk/src/main/java/org/apache/commons/math:
optimization/direct/PowellOptimizer.java util/MultidimensionalCounter.java
Author: sebb
Date: Fri Oct 1 13:09:25 2010
New Revision: 1003526
URL: http://svn.apache.org/viewvc?rev=1003526&view=rev
Log:
Java 1.5 does not support Arrays.copyOf()
Modified:
commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java
commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java?rev=1003526&r1=1003525&r2=1003526&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java Fri Oct 1 13:09:25 2010
@@ -17,8 +17,6 @@
package org.apache.commons.math.optimization.direct;
-import java.util.Arrays;
-
import org.apache.commons.math.FunctionEvaluationException;
import org.apache.commons.math.util.FastMath;
import org.apache.commons.math.analysis.UnivariateRealFunction;
@@ -138,7 +136,7 @@ public class PowellOptimizer
double alphaMin = 0;
for (int i = 0; i < n; i++) {
- final double[] d = Arrays.copyOf(direc[i], n);
+ final double[] d = /* Arrays.*/ copyOf(direc[i], n); // Java 1.5 does not support Arrays.copyOf()
fX2 = fVal;
@@ -284,4 +282,18 @@ public class PowellOptimizer
bracket.getMid());
}
}
+
+ /**
+ * Java 1.5 does not support Arrays.copyOf()
+ *
+ * @param source the array to be copied
+ * @param newLen the length of the copy to be returned
+ * @return the copied array, truncated or padded as necessary.
+ */
+ private double[] copyOf(double[] source, int newLen) {
+ double[] output = new double[newLen];
+ System.arraycopy(source, 0, output, 0, Math.min(source.length, newLen));
+ return output;
+ }
+
}
Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java?rev=1003526&r1=1003525&r2=1003526&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java Fri Oct 1 13:09:25 2010
@@ -17,7 +17,6 @@
package org.apache.commons.math.util;
-import java.util.Arrays;
import org.apache.commons.math.exception.DimensionMismatchException;
import org.apache.commons.math.exception.OutOfRangeException;
import org.apache.commons.math.exception.NotStrictlyPositiveException;
@@ -129,7 +128,7 @@ public class MultidimensionalCounter imp
* @return the indices within the multidimensional counter.
*/
public int[] getCounts() {
- return Arrays.copyOf(counter, dimension);
+ return /* Arrays.*/ copyOf(counter, dimension); // Java 1.5 does not support Arrays.copyOf()
}
/**
@@ -164,7 +163,7 @@ public class MultidimensionalCounter imp
*/
public MultidimensionalCounter(int ... size) {
dimension = size.length;
- this.size = Arrays.copyOf(size, dimension);
+ this.size = /* Arrays.*/ copyOf(size, dimension); // Java 1.5 does not support Arrays.copyOf()
uniCounterOffset = new int[dimension];
@@ -286,7 +285,7 @@ public class MultidimensionalCounter imp
* @return the sizes of the multidimensional counter in each dimension.
*/
public int[] getSizes() {
- return Arrays.copyOf(size, dimension);
+ return /* Arrays.*/ copyOf(size, dimension); // Java 1.5 does not support Arrays.copyOf()
}
/**
@@ -300,4 +299,18 @@ public class MultidimensionalCounter imp
}
return sb.toString();
}
+
+ /**
+ * Java 1.5 does not support Arrays.copyOf()
+ *
+ * @param source the array to be copied
+ * @param newLen the length of the copy to be returned
+ * @return the copied array, truncated or padded as necessary.
+ */
+ private int[] copyOf(int[] source, int newLen) {
+ int[] output = new int[newLen];
+ System.arraycopy(source, 0, output, 0, Math.min(source.length, newLen));
+ return output;
+ }
+
}