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
This commit is contained in:
Phil Steitz 2004-10-10 18:00:33 +00:00
parent 78677f2223
commit 4fe1f135a3
1 changed files with 21 additions and 19 deletions

View File

@ -46,7 +46,7 @@ import org.apache.commons.math.util.MathUtils;
* is 0-based -- e.g., <code>getEntry(0, 0)</code> * is 0-based -- e.g., <code>getEntry(0, 0)</code>
* returns the element in the first row, first column of the matrix.</li></ul> * returns the element in the first row, first column of the matrix.</li></ul>
* *
* @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 { public class RealMatrixImpl implements RealMatrix, Serializable {
@ -88,15 +88,15 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
} }
/** /**
* Create a new RealMatrix using the <code>data</code> as the underlying * Create a new RealMatrix using the input array as the underlying
* data array. * data array.
* <p> * <p>
* The input array is copied, not referenced. * The input array is copied, not referenced.
* *
* @param d data for new matrix * @param d data for new matrix
* @throws IllegalArgumentException if data is not rectangular (not all * @throws IllegalArgumentException if <code>data</code> is not rectangular
* rows have the same length) or data is empty * (not all rows have the same length) or empty
* @throws NullPointerException if data is null * @throws NullPointerException if <code>data</code> is null
*/ */
public RealMatrixImpl(double[][] d) { public RealMatrixImpl(double[][] d) {
int nRows = d.length; int nRows = d.length;
@ -344,9 +344,9 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
*/ */
public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn, public RealMatrix getSubMatrix(int startRow, int endRow, int startColumn,
int endColumn) throws MatrixIndexException { int endColumn) throws MatrixIndexException {
if (startRow < 0 || startRow > endRow || endRow > data.length if (startRow < 0 || startRow > endRow || endRow > data.length ||
|| startColumn < 0 || startColumn > endColumn startColumn < 0 || startColumn > endColumn ||
|| endColumn > data[0].length ) { endColumn > data[0].length ) {
throw new MatrixIndexException( throw new MatrixIndexException(
"invalid row or column index selection"); "invalid row or column index selection");
} }
@ -849,20 +849,22 @@ public class RealMatrixImpl implements RealMatrix, Serializable {
public String toString() { public String toString() {
StringBuffer res = new StringBuffer(); StringBuffer res = new StringBuffer();
res.append("RealMatrixImpl{"); res.append("RealMatrixImpl{");
for (int i = 0; i < data.length; i++) { if (data != null) {
if (i > 0) for (int i = 0; i < data.length; i++) {
res.append(","); if (i > 0)
res.append("{");
for (int j = 0; j < data[0].length; j++) {
if (j > 0)
res.append(","); res.append(",");
res.append(data[i][j]); res.append("{");
} //for for (int j = 0; j < data[0].length; j++) {
res.append("}"); if (j > 0)
} //for res.append(",");
res.append(data[i][j]);
}
res.append("}");
}
}
res.append("}"); res.append("}");
return res.toString(); return res.toString();
} //toString }
/** /**
* Returns true iff <code>object</code> is a * Returns true iff <code>object</code> is a