From 152073fa08a8218dda7f2f90a0109cf1855d201e Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Wed, 6 Jan 2016 12:23:48 +0100 Subject: [PATCH] Use MapArrays utility methods for building arrays. --- .../commons/math4/ode/FieldEquationsMapper.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java b/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java index eba2ad608..a17ceb386 100644 --- a/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java +++ b/src/main/java/org/apache/commons/math4/ode/FieldEquationsMapper.java @@ -18,7 +18,6 @@ package org.apache.commons.math4.ode; import java.io.Serializable; -import java.lang.reflect.Array; import org.apache.commons.math4.RealFieldElement; import org.apache.commons.math4.exception.MathIllegalArgumentException; @@ -35,7 +34,7 @@ import org.apache.commons.math4.util.MathArrays; * @param the type of the field elements * @since 3.6 */ -class FieldEquationsMapper> implements Serializable { +public class FieldEquationsMapper> implements Serializable { /** Serializable UID. */ private static final long serialVersionUID = 20151114L; @@ -119,8 +118,7 @@ class FieldEquationsMapper> implements Serializabl if (n < 2) { return new FieldODEState(t, state); } else { - @SuppressWarnings("unchecked") - final T[][] secondaryState = (T[][]) Array.newInstance(t.getField().getRuntimeClass(), n - 1); + final T[][] secondaryState = MathArrays.buildArray(t.getField(), n - 1, -1); while (++index < n) { secondaryState[index - 1] = extractEquationData(index, y); } @@ -142,10 +140,8 @@ class FieldEquationsMapper> implements Serializabl if (n < 2) { return new FieldODEStateAndDerivative(t, state, derivative); } else { - @SuppressWarnings("unchecked") - final T[][] secondaryState = (T[][]) Array.newInstance(t.getField().getRuntimeClass(), n - 1); - @SuppressWarnings("unchecked") - final T[][] secondaryDerivative = (T[][]) Array.newInstance(t.getField().getRuntimeClass(), n - 1); + final T[][] secondaryState = MathArrays.buildArray(t.getField(), n - 1, -1); + final T[][] secondaryDerivative = MathArrays.buildArray(t.getField(), n - 1, -1); while (++index < getNumberOfEquations()) { secondaryState[index - 1] = extractEquationData(index, y); secondaryDerivative[index - 1] = extractEquationData(index, yDot);