improved error messages consistency

fixed checkstyle warnings

git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@744724 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Luc Maisonobe 2009-02-15 19:15:51 +00:00
parent 59e6743960
commit 0992284ca5
4 changed files with 43 additions and 16 deletions

View File

@ -189,6 +189,16 @@ public class MessagesResources_fr
{ "matrix is singular", { "matrix is singular",
"matrice singuli\u00e8re" }, "matrice singuli\u00e8re" },
// org.apache.commons.math.linear.CholeskyDecompositionImpl
// org.apache.commons.math.linear.EigenDecompositionImpl
// org.apache.commons.math.linear.LUDecompositionImpl
// org.apache.commons.math.linear.QRDecompositionImpl
// org.apache.commons.math.linear.SingularValueDecompositionImpl
{ "vector length mismatch: got {0} but expected {1}",
"dimension de vecteur erronn\u00e9e : {0} \u00e0 la place de {1}" },
{ "dimensions mismatch: got {0}x{1} but expected {2}x{3}",
"dimensions erronn\u00e9es : {0}x{1} \u00e0 la place de {2}x{3}" },
// org.apache.commons.math.linear.RealVectorImpl // org.apache.commons.math.linear.RealVectorImpl
{ "index {0} out of allowed range [{1}, {2}]", { "index {0} out of allowed range [{1}, {2}]",
"index {0} hors de la plage autoris\u00e9e [{1}, {2}]" }, "index {0} hors de la plage autoris\u00e9e [{1}, {2}]" },

View File

@ -22,6 +22,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.MaxIterationsExceededException; import org.apache.commons.math.MaxIterationsExceededException;
import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.MathUtils;
@ -404,7 +405,9 @@ public class EigenDecompositionImpl implements EigenDecomposition {
final int m = realEigenvalues.length; final int m = realEigenvalues.length;
if (b.length != m) { if (b.length != m) {
throw new IllegalArgumentException("constant vector has wrong length"); throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
new Object[] { b.length, m });
} }
final double[] bp = new double[m]; final double[] bp = new double[m];
@ -438,7 +441,9 @@ public class EigenDecompositionImpl implements EigenDecomposition {
final int m = realEigenvalues.length; final int m = realEigenvalues.length;
if (b.getDimension() != m) { if (b.getDimension() != m) {
throw new IllegalArgumentException("constant vector has wrong length"); throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
new Object[] { b.getDimension(), m });
} }
final double[] bp = new double[m]; final double[] bp = new double[m];
@ -472,7 +477,12 @@ public class EigenDecompositionImpl implements EigenDecomposition {
final int m = realEigenvalues.length; final int m = realEigenvalues.length;
if (b.getRowDimension() != m) { if (b.getRowDimension() != m) {
throw new IllegalArgumentException("Incorrect row dimension"); throw MathRuntimeException.createIllegalArgumentException(
"dimensions mismatch: got {0}x{1} but expected {2}x{3}",
new Object[] {
b.getRowDimension(), b.getColumnDimension(),
m, "n"
});
} }
final int nColB = b.getColumnDimension(); final int nColB = b.getColumnDimension();

View File

@ -18,6 +18,7 @@
package org.apache.commons.math.linear; package org.apache.commons.math.linear;
import org.apache.commons.math.ConvergenceException; import org.apache.commons.math.ConvergenceException;
import org.apache.commons.math.MathRuntimeException;
import org.apache.commons.math.util.MathUtils; import org.apache.commons.math.util.MathUtils;
/** /**
@ -336,7 +337,9 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
throws IllegalArgumentException, InvalidMatrixException { throws IllegalArgumentException, InvalidMatrixException {
if (b.length != singularValues.length) { if (b.length != singularValues.length) {
throw new IllegalArgumentException("constant vector has wrong length"); throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
new Object[] { b.length, singularValues.length });
} }
final double[] w = uT.operate(b); final double[] w = uT.operate(b);
@ -363,7 +366,9 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
throws IllegalArgumentException, InvalidMatrixException { throws IllegalArgumentException, InvalidMatrixException {
if (b.getDimension() != singularValues.length) { if (b.getDimension() != singularValues.length) {
throw new IllegalArgumentException("constant vector has wrong length"); throw MathRuntimeException.createIllegalArgumentException(
"vector length mismatch: got {0} but expected {1}",
new Object[] { b.getDimension(), singularValues.length });
} }
final RealVector w = uT.operate(b); final RealVector w = uT.operate(b);
@ -390,7 +395,12 @@ public class SingularValueDecompositionImpl implements SingularValueDecompositio
throws IllegalArgumentException, InvalidMatrixException { throws IllegalArgumentException, InvalidMatrixException {
if (b.getRowDimension() != singularValues.length) { if (b.getRowDimension() != singularValues.length) {
throw new IllegalArgumentException("Incorrect row dimension"); throw MathRuntimeException.createIllegalArgumentException(
"dimensions mismatch: got {0}x{1} but expected {2}x{3}",
new Object[] {
b.getRowDimension(), b.getColumnDimension(),
singularValues.length, "n"
});
} }
final RealMatrix w = uT.multiply(b); final RealMatrix w = uT.multiply(b);

View File

@ -1191,8 +1191,8 @@ public class SparseRealVector implements RealVector {
private void checkIndex(final int index) throws MatrixIndexException { private void checkIndex(final int index) throws MatrixIndexException {
if (index < 0 || index >= getDimension()) { if (index < 0 || index >= getDimension()) {
throw new MatrixIndexException( throw new MatrixIndexException(
"index {0} out of allowed range [{1}, {2}]", new Object[] { "index {0} out of allowed range [{1}, {2}]",
index, 0, getDimension() - 1 }); new Object[] { index, 0, getDimension() - 1 });
} }
} }
@ -1206,8 +1206,9 @@ public class SparseRealVector implements RealVector {
*/ */
protected void checkVectorDimensions(int n) throws IllegalArgumentException { protected void checkVectorDimensions(int n) throws IllegalArgumentException {
if (getDimension() != n) { if (getDimension() != n) {
throw new IllegalArgumentException("vector dimension is " throw MathRuntimeException.createIllegalArgumentException(
+ getDimension() + ", not " + n + " as expected"); "vector length mismatch: got {0} but expected {1}",
new Object[] { getDimension(), n });
} }
} }
@ -1216,9 +1217,7 @@ public class SparseRealVector implements RealVector {
return getData(); return getData();
} }
/* (non-Javadoc) /** {@inheritDoc} */
* @see java.lang.Object#hashCode()
*/
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 31; final int prime = 31;
@ -1230,9 +1229,7 @@ public class SparseRealVector implements RealVector {
return result; return result;
} }
/* (non-Javadoc) /** {@inheritDoc} */
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override @Override
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (this == obj) if (this == obj)