From 4fe1f135a368aa3ad0cf57dc9e97e474c86954da Mon Sep 17 00:00:00 2001 From: Phil Steitz Date: Sun, 10 Oct 2004 18:00:33 +0000 Subject: [PATCH] Formatting, javadoc, plus fix for toString to handle empty matrix. git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/math/trunk@141464 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/linear/RealMatrixImpl.java | 40 ++++++++++--------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java index 42d3ac311..fd5dbada5 100644 --- a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java @@ -46,7 +46,7 @@ import org.apache.commons.math.util.MathUtils; * is 0-based -- e.g., getEntry(0, 0) * returns the element in the first row, first column of the matrix. * - * @version $Revision: 1.31 $ $Date: 2004/10/10 05:23:16 $ + * @version $Revision: 1.32 $ $Date: 2004/10/10 18:00:33 $ */ public class RealMatrixImpl implements RealMatrix, Serializable { @@ -88,15 +88,15 @@ public class RealMatrixImpl implements RealMatrix, Serializable { } /** - * Create a new RealMatrix using the data as the underlying + * Create a new RealMatrix using the input array as the underlying * data array. *

* The input array is copied, not referenced. * * @param d data for new matrix - * @throws IllegalArgumentException if data is not rectangular (not all - * rows have the same length) or data is empty - * @throws NullPointerException if data is null + * @throws IllegalArgumentException if data is not rectangular + * (not all rows have the same length) or empty + * @throws NullPointerException if data is null */ public RealMatrixImpl(double[][] d) { int nRows = d.length; @@ -344,9 +344,9 @@ public class RealMatrixImpl implements RealMatrix, Serializable { */ public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, int endColumn) throws MatrixIndexException { - if (startRow < 0 || startRow > endRow || endRow > data.length - || startColumn < 0 || startColumn > endColumn - || endColumn > data[0].length ) { + if (startRow < 0 || startRow > endRow || endRow > data.length || + startColumn < 0 || startColumn > endColumn || + endColumn > data[0].length ) { throw new MatrixIndexException( "invalid row or column index selection"); } @@ -849,20 +849,22 @@ public class RealMatrixImpl implements RealMatrix, Serializable { public String toString() { StringBuffer res = new StringBuffer(); res.append("RealMatrixImpl{"); - for (int i = 0; i < data.length; i++) { - if (i > 0) - res.append(","); - res.append("{"); - for (int j = 0; j < data[0].length; j++) { - if (j > 0) + if (data != null) { + for (int i = 0; i < data.length; i++) { + if (i > 0) res.append(","); - res.append(data[i][j]); - } //for - res.append("}"); - } //for + res.append("{"); + for (int j = 0; j < data[0].length; j++) { + if (j > 0) + res.append(","); + res.append(data[i][j]); + } + res.append("}"); + } + } res.append("}"); return res.toString(); - } //toString + } /** * Returns true iff object is a