diff --git a/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java b/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java index 0dd780690..c317ef445 100644 --- a/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java +++ b/src/main/java/org/apache/commons/math/exception/MatrixDimensionMismatchException.java @@ -50,24 +50,24 @@ public class MatrixDimensionMismatchException extends MultiDimensionMismatchExce * @return the expected row dimension. */ public int getWrongRowDimension() { - return getWrongDimensions()[0]; + return getWrongDimension(0); } /** * @return the expected row dimension. */ public int getExpectedRowDimension() { - return getExpectedDimensions()[0]; + return getExpectedDimension(0); } /** * @return the wrong column dimension. */ public int getWrongColumnDimension() { - return getWrongDimensions()[1]; + return getWrongDimension(1); } /** * @return the expected column dimension. */ public int getExpectedColumnDimension() { - return getExpectedDimensions()[1]; + return getExpectedDimension(1); } } diff --git a/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java b/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java index 370ddf417..07843ee3f 100644 --- a/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java +++ b/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java @@ -62,15 +62,29 @@ public class MultiDimensionMismatchException extends MathIllegalArgumentExceptio } /** - * @return a reference to the array containing the wrong dimensions. + * @return an array containing the wrong dimensions. */ public Integer[] getWrongDimensions() { - return wrong; + return wrong.clone(); } /** - * @return a reference to the array containing the expected dimensions. + * @return an array containing the expected dimensions. */ public Integer[] getExpectedDimensions() { - return expected; + return expected.clone(); + } + + /** + * @param index Dimension index. + * @return the wrong dimension stored at {@code index}. + */ + public int getWrongDimension(int index) { + return wrong[index]; + } + /** + * @return an the expected dimension stored at {@code index}.. + */ + public int getExpectedDimension(int index) { + return expected[index]; } }