backported r1003526 from trunk to branch 2.X
Java 1.5 does not support Arrays.copyOf() git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_X@1003895 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b4681e50ff
commit
ad59080231
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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<Integer> {
|
|||
* @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<Integer> {
|
|||
*/
|
||||
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<Integer> {
|
|||
* @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<Integer> {
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue