psteitz 2004/10/24 22:33:24
Modified: math/src/java/org/apache/commons/math/linear
BigMatrixImpl.java
Log:
Added checks for validity of arrays supplied to constructors.
Revision Changes Path
1.9 +58 -1
jakarta-commons/math/src/java/org/apache/commons/math/linear/BigMatrixImpl.java
Index: BigMatrixImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/math/src/java/org/apache/commons/math/linear/BigMatrixImpl.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- BigMatrixImpl.java 25 Oct 2004 03:12:28 -0000 1.8
+++ BigMatrixImpl.java 25 Oct 2004 05:33:24 -0000 1.9
@@ -103,8 +103,27 @@
* The input array is copied, not referenced.
*
* @param d data for new matrix
+ * @throws IllegalArgumentException if <code>d</code> is not rectangular
+ * (not all rows have the same length) or empty
+ * @throws NullPointerException if <code>d</code> is null
*/
public BigMatrixImpl(BigDecimal[][] d) {
+ int nRows = d.length;
+ if (nRows == 0) {
+ throw new IllegalArgumentException(
+ "Matrix must have at least one row.");
+ }
+ int nCols = d[0].length;
+ if (nCols == 0) {
+ throw new IllegalArgumentException(
+ "Matrix must have at least one column.");
+ }
+ for (int row = 1; row < nRows; row++) {
+ if (d[row].length != nCols) {
+ throw new IllegalArgumentException(
+ "All input rows must have the same length.");
+ }
+ }
this.copyIn(d);
lu = null;
}
@@ -116,8 +135,27 @@
* The input array is copied, not referenced.
*
* @param d data for new matrix
+ * @throws IllegalArgumentException if <code>d</code> is not rectangular
+ * (not all rows have the same length) or empty
+ * @throws NullPointerException if <code>d</code> is null
*/
public BigMatrixImpl(double[][] d) {
+ int nRows = d.length;
+ if (nRows == 0) {
+ throw new IllegalArgumentException(
+ "Matrix must have at least one row.");
+ }
+ int nCols = d[0].length;
+ if (nCols == 0) {
+ throw new IllegalArgumentException(
+ "Matrix must have at least one column.");
+ }
+ for (int row = 1; row < nRows; row++) {
+ if (d[row].length != nCols) {
+ throw new IllegalArgumentException(
+ "All input rows must have the same length.");
+ }
+ }
this.copyIn(d);
lu = null;
}
@@ -127,8 +165,27 @@
* <code>data</code> as the underlying data array.
*
* @param d data for new matrix
+ * @throws IllegalArgumentException if <code>d</code> is not rectangular
+ * (not all rows have the same length) or empty
+ * @throws NullPointerException if <code>d</code> is null
*/
public BigMatrixImpl(String[][] d) {
+ int nRows = d.length;
+ if (nRows == 0) {
+ throw new IllegalArgumentException(
+ "Matrix must have at least one row.");
+ }
+ int nCols = d[0].length;
+ if (nCols == 0) {
+ throw new IllegalArgumentException(
+ "Matrix must have at least one column.");
+ }
+ for (int row = 1; row < nRows; row++) {
+ if (d[row].length != nCols) {
+ throw new IllegalArgumentException(
+ "All input rows must have the same length.");
+ }
+ }
this.copyIn(d);
lu = null;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]