replaced Object[] parameters by variable arguments in exceptions constructors

this allows simpler error declaration and removes the need for the strange
null argument with fixed messages

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk/src/experimental@746578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-02-21 20:01:14 +00:00
parent f99927bd5e
commit fd82d75e53
1 changed files with 45 additions and 72 deletions

View File

@ -173,11 +173,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
// create storage array // create storage array
final int expectedLength = tileNumber * tileNumber * tileSizeRows * tileSizeColumns; final int expectedLength = tileNumber * tileNumber * tileSizeRows * tileSizeColumns;
if (data.length != expectedLength) { if (data.length != expectedLength) {
throw MathRuntimeException.createIllegalArgumentException("wrong array size (got {0}, expected {1})", throw MathRuntimeException.createIllegalArgumentException(
new Object[] { "wrong array size (got {0}, expected {1})",
data.length, data.length, expectedLength);
expectedLength
});
} }
if (copyArray) { if (copyArray) {
@ -222,7 +220,7 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
if (length != columns) { if (length != columns) {
throw MathRuntimeException.createIllegalArgumentException( throw MathRuntimeException.createIllegalArgumentException(
"some rows have length {0} while others have length {1}", "some rows have length {0} while others have length {1}",
new Object[] { columns, length }); columns, length);
} }
} }
@ -1028,10 +1026,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
checkSubMatrixIndex(row, endRow, column, endColumn); checkSubMatrixIndex(row, endRow, column, endColumn);
for (final double[] subRow : subMatrix) { for (final double[] subRow : subMatrix) {
if (subRow.length != refLength) { if (subRow.length != refLength) {
throw MathRuntimeException.createIllegalArgumentException("some rows have length {0} while others have length {1}", throw MathRuntimeException.createIllegalArgumentException(
new Object[] { "some rows have length {0} while others have length {1}",
refLength, subRow.length refLength, subRow.length);
});
} }
} }
@ -1118,12 +1115,10 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
final int nCols = getColumnDimension(); final int nCols = getColumnDimension();
if ((matrix.getRowDimension() != 1) || if ((matrix.getRowDimension() != 1) ||
(matrix.getColumnDimension() != nCols)) { (matrix.getColumnDimension() != nCols)) {
throw new InvalidMatrixException("dimensions mismatch: got {0}x{1} but expected {2}x{3}", throw new InvalidMatrixException(
new Object[] { "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
matrix.getRowDimension(), matrix.getRowDimension(), matrix.getColumnDimension(),
matrix.getColumnDimension(), 1, nCols);
1, nCols
});
} }
// a row matrix has always only one large tile, // a row matrix has always only one large tile,
@ -1196,12 +1191,10 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
final int nRows = getRowDimension(); final int nRows = getRowDimension();
if ((matrix.getRowDimension() != nRows) || if ((matrix.getRowDimension() != nRows) ||
(matrix.getColumnDimension() != 1)) { (matrix.getColumnDimension() != 1)) {
throw new InvalidMatrixException("dimensions mismatch: got {0}x{1} but expected {2}x{3}", throw new InvalidMatrixException(
new Object[] { "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
matrix.getRowDimension(), matrix.getRowDimension(), matrix.getColumnDimension(),
matrix.getColumnDimension(), nRows, 1);
nRows, 1
});
} }
// a column matrix has always only one large tile, // a column matrix has always only one large tile,
@ -1229,11 +1222,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
} catch (ClassCastException cce) { } catch (ClassCastException cce) {
checkRowIndex(row); checkRowIndex(row);
if (vector.getDimension() != columns) { if (vector.getDimension() != columns) {
throw new InvalidMatrixException("dimensions mismatch: got {0}x{1} but expected {2}x{3}", throw new InvalidMatrixException(
new Object[] { "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
1, vector.getDimension(), 1, vector.getDimension(), 1, columns);
1, columns
});
} }
// perform copy tile-wise, to ensure good cache behavior // perform copy tile-wise, to ensure good cache behavior
@ -1260,11 +1251,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
} catch (ClassCastException cce) { } catch (ClassCastException cce) {
checkColumnIndex(column); checkColumnIndex(column);
if (vector.getDimension() != rows) { if (vector.getDimension() != rows) {
throw new InvalidMatrixException("dimensions mismatch: got {0}x{1} but expected {2}x{3}", throw new InvalidMatrixException(
new Object[] { "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
vector.getDimension(), 1, vector.getDimension(), 1, rows, 1);
rows, 1
});
} }
// perform copy tile-wise, to ensure good cache behavior // perform copy tile-wise, to ensure good cache behavior
@ -1311,11 +1300,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
checkRowIndex(row); checkRowIndex(row);
if (array.length != columns) { if (array.length != columns) {
throw new InvalidMatrixException("dimensions mismatch: got {0}x{1} but expected {2}x{3}", throw new InvalidMatrixException(
new Object[] { "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
1, array.length, 1, array.length, 1, columns);
1, columns
});
} }
// perform copy tile-wise, to ensure good cache behavior // perform copy tile-wise, to ensure good cache behavior
@ -1362,11 +1349,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
checkColumnIndex(column); checkColumnIndex(column);
if (array.length != rows) { if (array.length != rows) {
throw new InvalidMatrixException("dimensions mismatch: got {0}x{1} but expected {2}x{3}", throw new InvalidMatrixException(
new Object[] { "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
array.length, 1, array.length, 1, rows, 1);
rows, 1
});
} }
// perform copy tile-wise, to ensure good cache behavior // perform copy tile-wise, to ensure good cache behavior
@ -1388,11 +1373,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
public double getEntry(final int row, final int column) public double getEntry(final int row, final int column)
throws MatrixIndexException { throws MatrixIndexException {
if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) { if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
throw new MatrixIndexException("no entry at indices ({0}, {1}) in a {2}x{3} matrix", throw new MatrixIndexException(
new Object[] { "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, row, column, getRowDimension(), getColumnDimension());
getRowDimension(), getColumnDimension()
});
} }
return data[index(row, column)]; return data[index(row, column)];
} }
@ -1401,11 +1384,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
public void setEntry(final int row, final int column, final double value) public void setEntry(final int row, final int column, final double value)
throws MatrixIndexException { throws MatrixIndexException {
if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) { if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
throw new MatrixIndexException("no entry at indices ({0}, {1}) in a {2}x{3} matrix", throw new MatrixIndexException(
new Object[] { "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, row, column, getRowDimension(), getColumnDimension());
getRowDimension(), getColumnDimension()
});
} }
data[index(row, column)] = value; data[index(row, column)] = value;
} }
@ -1414,11 +1395,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
public void addToEntry(final int row, final int column, final double increment) public void addToEntry(final int row, final int column, final double increment)
throws MatrixIndexException { throws MatrixIndexException {
if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) { if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
throw new MatrixIndexException("no entry at indices ({0}, {1}) in a {2}x{3} matrix", throw new MatrixIndexException(
new Object[] { "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, row, column, getRowDimension(), getColumnDimension());
getRowDimension(), getColumnDimension()
});
} }
data[index(row, column)] += increment; data[index(row, column)] += increment;
} }
@ -1427,11 +1406,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
public void multiplyEntry(final int row, final int column, final double factor) public void multiplyEntry(final int row, final int column, final double factor)
throws MatrixIndexException { throws MatrixIndexException {
if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) { if ((row < 0) || (row >= rows) || (column < 0) || (column >= columns)) {
throw new MatrixIndexException("no entry at indices ({0}, {1}) in a {2}x{3} matrix", throw new MatrixIndexException(
new Object[] { "no entry at indices ({0}, {1}) in a {2}x{3} matrix",
row, column, row, column, getRowDimension(), getColumnDimension());
getRowDimension(), getColumnDimension()
});
} }
data[index(row, column)] *= factor; data[index(row, column)] *= factor;
} }
@ -1486,11 +1463,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
throws IllegalArgumentException { throws IllegalArgumentException {
if (v.length != columns) { if (v.length != columns) {
throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" + throw MathRuntimeException.createIllegalArgumentException(
" got {0} but expected {1}", "vector length mismatch: got {0} but expected {1}",
new Object[] { v.length, columns);
v.length, columns
});
} }
final double[] out = new double[rows]; final double[] out = new double[rows];
@ -1531,11 +1506,9 @@ public class RecursiveLayoutRealMatrix extends AbstractRealMatrix implements Ser
throws IllegalArgumentException { throws IllegalArgumentException {
if (v.length != rows) { if (v.length != rows) {
throw MathRuntimeException.createIllegalArgumentException("vector length mismatch:" + throw MathRuntimeException.createIllegalArgumentException(
" got {0} but expected {1}", "vector length mismatch: got {0} but expected {1}",
new Object[] { v.length, rows);
v.length, rows
});
} }
final double[] out = new double[columns]; final double[] out = new double[columns];