diff --git a/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java b/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java index 318addeb0..79292a702 100644 --- a/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java +++ b/src/main/java/org/apache/commons/math/optimization/direct/PowellOptimizer.java @@ -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.MaxIterationsExceededException; import org.apache.commons.math.analysis.UnivariateRealFunction; @@ -114,7 +112,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; @@ -287,4 +285,18 @@ public class PowellOptimizer return valueAtOptimum; } } + + /** + * 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; + } + } diff --git a/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java b/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java index 28f673b27..437a8553e 100644 --- a/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java +++ b/src/main/java/org/apache/commons/math/util/MultidimensionalCounter.java @@ -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 implements Iterable { * @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 implements Iterable { */ 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 implements Iterable { * @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 implements Iterable { } 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; + } + }