From 6b07dd2122f954a4ff864fc6db8468d3d51aca78 Mon Sep 17 00:00:00 2001 From: Luc Maisonobe Date: Sat, 8 Nov 2008 20:42:55 +0000 Subject: [PATCH] improved error messages git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/branches/MATH_2_0@712430 13f79535-47bb-0310-9956-ffa450edef68 --- .../commons/math/MessagesResources_fr.java | 46 ++++++++++++++++++- .../UnivariateRealIntegratorImpl.java | 6 ++- .../analysis/UnivariateRealSolverImpl.java | 5 +- .../commons/math/linear/BigMatrixImpl.java | 11 ++++- .../math/linear/LUDecompositionImpl.java | 4 +- .../math/linear/QRDecompositionImpl.java | 4 +- .../commons/math/linear/RealMatrixImpl.java | 11 ++++- .../random/EmpiricalDistributionImpl.java | 3 +- .../commons/math/random/ValueServer.java | 16 +++++-- .../MultivariateSummaryStatistics.java | 5 +- .../stat/descriptive/SummaryStatistics.java | 4 +- .../descriptive/moment/GeometricMean.java | 5 +- .../stat/descriptive/moment/Kurtosis.java | 11 +++-- 13 files changed, 106 insertions(+), 25 deletions(-) diff --git a/src/java/org/apache/commons/math/MessagesResources_fr.java b/src/java/org/apache/commons/math/MessagesResources_fr.java index ee0daae57..9de6fca43 100644 --- a/src/java/org/apache/commons/math/MessagesResources_fr.java +++ b/src/java/org/apache/commons/math/MessagesResources_fr.java @@ -174,6 +174,8 @@ public class MessagesResources_fr // org.apache.commons.math.linear.EigenDecompositionImpl { "negative element on decomposed tridiagonal of {0}x{1} matrix", "\u00e9l\u00e9ment n\u00e9gatif dans la d\u00e9composition tri-diagonale d''une matrice {0}x{1}" }, + { "internal error: please file a bug report at https://issues.apache.org/jira/browse/MATH", + "erreur interne : veuillez enregistrer un rapport de bogue sur https://issues.apache.org/jira/browse/MATH" }, // org.apache.commons.math.linear.NonSquareMatrixException { "a {0}x{1} matrix was provided instead of a square matrix", @@ -256,11 +258,51 @@ public class MessagesResources_fr "norme nulle pour un axe de rotation" }, // org.apache.commons.math.geometry.Vector3D - // org.apache.commons.math.linear.RealVectorImpl + // org.apache.commons.math.linear.RealVectorImpl { "cannot normalize a zero norm vector", "impossible de normer un vecteur de norme nulle" }, { "zero norm", - "norme nulle" } + "norme nulle" }, + + // org.apache.commons.math.analysis.UnivariateRealIntegratorImpl + // org.apache.commons.math.analysis.UnivariateRealSolverImpl + { "no result available", + "aucun r\u00e9sultat n''est disponible" }, + + // org.apache.commons.math.linear.BigMatrixImpl + { "first {0} rows are not initialized yet", + "les {0} premi\u00e8res lignes ne sont pas encore initialis\u00e9es" }, + { "first {0} columns are not initialized yet", + "les {0} premi\u00e8res colonnes ne sont pas encore initialis\u00e9es" }, + + // org.apache.commons.math.linear.EigenDecompositionImpl + // org.apache.commons.math.linear.LUDecompositionImpl + // org.apache.commons.math.linear.QRDecompositionImpl + // org.apache.commons.math.linear.SingularValueDecompositionImpl + { "no matrix have been decomposed yet", + "aucune matrice n''a encore \u00e9t\u00e9 d\u00e9compos\u00e9e" }, + + // org.apache.commons.math.random.EmpiricalDistributionImpl + { "distribution not loaded", + "aucune distribution n''a \u00e9t\u00e9 charg\u00e9e" }, + + // org.apache.commons.math.random.ValueServer + { "unknown mode {0}, known modes: {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) and {11} ({12})", + "mode {0} inconnu, modes connus : {1} ({2}), {3} ({4}), {5} ({6}), {7} ({8}), {9} ({10}) et {11} ({12})" }, + { "digest not initialized", + "mod\u00e8le empirique non initialis\u00e9" }, + + // org.apache.commons.math.stat.descriptive.moment.GeometricMean + // org.apache.commons.math.stat.descriptive.MultivariateSummaryStatistics + // org.apache.commons.math.stat.descriptive.SummaryStatistics + { "{0} values have been added before statistic is configured", + "{0} valeurs ont \u00e9t\u00e9 ajout\u00e9es avant que la statistique ne soit configur\u00e9e" }, + + // org.apache.commons.math.stat.descriptive.moment.Kurtosis + { "statistics constructed from external moments cannot be incremented", + "les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre incr\u00e9ment\u00e9es" }, + { "statistics constructed from external moments cannot be cleared", + "les statistiques bas\u00e9es sur des moments externes ne peuvent pas \u00eatre remises \u00e0 z\u00e9ro" } }; diff --git a/src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java b/src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java index 911c55bb6..693d99e1f 100644 --- a/src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java +++ b/src/java/org/apache/commons/math/analysis/UnivariateRealIntegratorImpl.java @@ -18,6 +18,8 @@ package org.apache.commons.math.analysis; import java.io.Serializable; +import org.apache.commons.math.MathRuntimeException; + /** * Provide a default implementation for several generic functions. * @@ -99,7 +101,7 @@ public abstract class UnivariateRealIntegratorImpl implements if (resultComputed) { return result; } else { - throw new IllegalStateException("No result available."); + throw MathRuntimeException.createIllegalStateException("no result available", null); } } @@ -113,7 +115,7 @@ public abstract class UnivariateRealIntegratorImpl implements if (resultComputed) { return iterationCount; } else { - throw new IllegalStateException("No result available."); + throw MathRuntimeException.createIllegalStateException("no result available", null); } } diff --git a/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java b/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java index df10405fe..04bed1eab 100644 --- a/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java +++ b/src/java/org/apache/commons/math/analysis/UnivariateRealSolverImpl.java @@ -20,6 +20,7 @@ package org.apache.commons.math.analysis; import java.io.Serializable; import org.apache.commons.math.FunctionEvaluationException; +import org.apache.commons.math.MathRuntimeException; /** * Provide a default implementation for several functions useful to generic @@ -111,7 +112,7 @@ public abstract class UnivariateRealSolverImpl implements UnivariateRealSolver, if (resultComputed) { return result; } else { - throw new IllegalStateException("No result available"); + throw MathRuntimeException.createIllegalStateException("no result available", null); } } @@ -126,7 +127,7 @@ public abstract class UnivariateRealSolverImpl implements UnivariateRealSolver, if (resultComputed) { return iterationCount; } else { - throw new IllegalStateException("No result available"); + throw MathRuntimeException.createIllegalStateException("no result available", null); } } diff --git a/src/java/org/apache/commons/math/linear/BigMatrixImpl.java b/src/java/org/apache/commons/math/linear/BigMatrixImpl.java index f2ccf5250..f8f5fdfea 100644 --- a/src/java/org/apache/commons/math/linear/BigMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/BigMatrixImpl.java @@ -19,6 +19,8 @@ package org.apache.commons.math.linear; import java.io.Serializable; import java.math.BigDecimal; +import org.apache.commons.math.MathRuntimeException; + /** * Implementation of {@link BigMatrix} using a BigDecimal[][] array to store entries * and @@ -697,8 +699,13 @@ public class BigMatrixImpl implements BigMatrix, Serializable { } if (data == null) { - if ((row > 0) || (column > 0)) { - throw new IllegalStateException("matrix must be initialized to perform this method"); + if (row > 0) { + throw MathRuntimeException.createIllegalStateException("first {0} rows are not initialized yet", + new Object[] { row }); + } + if (column > 0) { + throw MathRuntimeException.createIllegalStateException("first {0} columns are not initialized yet", + new Object[] { column }); } data = new BigDecimal[nRows][nCols]; System.arraycopy(subMatrix, 0, data, 0, subMatrix.length); diff --git a/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java b/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java index 67526f9c3..e63da7e33 100644 --- a/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java +++ b/src/java/org/apache/commons/math/linear/LUDecompositionImpl.java @@ -17,6 +17,8 @@ package org.apache.commons.math.linear; +import org.apache.commons.math.MathRuntimeException; + /** * Calculates the LUP-decomposition of a square matrix. *

The LUP-decomposition of a matrix A consists of three matrices @@ -431,7 +433,7 @@ public class LUDecompositionImpl implements LUDecomposition { private void checkDecomposed() throws IllegalStateException { if (lu == null) { - throw new IllegalStateException("no matrix have been decomposed yet"); + throw MathRuntimeException.createIllegalStateException("no matrix have been decomposed yet", null); } } diff --git a/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java b/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java index 3990e538e..07d2f9aca 100644 --- a/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java +++ b/src/java/org/apache/commons/math/linear/QRDecompositionImpl.java @@ -17,6 +17,8 @@ package org.apache.commons.math.linear; +import org.apache.commons.math.MathRuntimeException; + /** * Calculates the QR-decomposition of a matrix. *

The QR-decomposition of a matrix A consists of two matrices Q and R @@ -443,7 +445,7 @@ public class QRDecompositionImpl implements QRDecomposition { private void checkDecomposed() throws IllegalStateException { if (qrt == null) { - throw new IllegalStateException("no matrix have been decomposed yet"); + throw MathRuntimeException.createIllegalStateException("no matrix have been decomposed yet", null); } } diff --git a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java index 38fa68a39..6822884f7 100644 --- a/src/java/org/apache/commons/math/linear/RealMatrixImpl.java +++ b/src/java/org/apache/commons/math/linear/RealMatrixImpl.java @@ -18,6 +18,8 @@ package org.apache.commons.math.linear; import java.io.Serializable; + +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.util.MathUtils; @@ -488,8 +490,13 @@ public class RealMatrixImpl implements RealMatrix, Serializable { } if (data == null) { - if ((row > 0) || (column > 0)) { - throw new IllegalStateException("matrix must be initialized to perform this method"); + if (row > 0) { + throw MathRuntimeException.createIllegalStateException("first {0} rows are not initialized yet", + new Object[] { row }); + } + if (column > 0) { + throw MathRuntimeException.createIllegalStateException("first {0} columns are not initialized yet", + new Object[] { column }); } data = new double[nRows][nCols]; System.arraycopy(subMatrix, 0, data, 0, subMatrix.length); diff --git a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java index aec4d2e36..d64b828b2 100644 --- a/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java +++ b/src/java/org/apache/commons/math/random/EmpiricalDistributionImpl.java @@ -413,7 +413,8 @@ public class EmpiricalDistributionImpl implements Serializable, EmpiricalDistrib public double getNextValue() throws IllegalStateException { if (!loaded) { - throw new IllegalStateException("distribution not loaded"); + throw MathRuntimeException.createIllegalStateException("distribution not loaded", + null); } // Start with a uniformly distributed random number in (0,1) diff --git a/src/java/org/apache/commons/math/random/ValueServer.java b/src/java/org/apache/commons/math/random/ValueServer.java index d4a3311e6..6e8269aff 100644 --- a/src/java/org/apache/commons/math/random/ValueServer.java +++ b/src/java/org/apache/commons/math/random/ValueServer.java @@ -106,8 +106,18 @@ public class ValueServer { case EXPONENTIAL_MODE: return getNextExponential(); case GAUSSIAN_MODE: return getNextGaussian(); case CONSTANT_MODE: return mu; - default: throw new IllegalStateException - ("Bad mode: " + mode); + default: throw MathRuntimeException.createIllegalStateException("unknown mode {0}, known modes: " + + "{1} ({2}), {3} ({4}), {5} ({6}), " + + "{7} ({8}), {9} ({10}) and {11} ({12})", + new Object[] { + mode, + "DIGEST_MODE", DIGEST_MODE, + "REPLAY_MODE", REPLAY_MODE, + "UNIFORM_MODE", UNIFORM_MODE, + "EXPONENTIAL_MODE", EXPONENTIAL_MODE, + "GAUSSIAN_MODE", GAUSSIAN_MODE, + "CONSTANT_MODE", CONSTANT_MODE + }); } } @@ -296,7 +306,7 @@ public class ValueServer { private double getNextDigest() { if ((empiricalDistribution == null) || (empiricalDistribution.getBinStats().size() == 0)) { - throw new IllegalStateException("Digest not initialized"); + throw MathRuntimeException.createIllegalStateException("digest not initialized", null); } return empiricalDistribution.getNextValue(); } diff --git a/src/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java b/src/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java index 1c75e74ed..316196bfb 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java +++ b/src/java/org/apache/commons/math/stat/descriptive/MultivariateSummaryStatistics.java @@ -20,6 +20,7 @@ import java.io.Serializable; import java.util.Arrays; import org.apache.commons.math.DimensionMismatchException; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.linear.RealMatrix; import org.apache.commons.math.stat.descriptive.moment.GeometricMean; import org.apache.commons.math.stat.descriptive.moment.Mean; @@ -609,8 +610,8 @@ public class MultivariateSummaryStatistics */ private void checkEmpty() { if (n > 0) { - throw new IllegalStateException( - "Implementations must be configured before values are added."); + throw MathRuntimeException.createIllegalStateException("{0} values have been added before statistic is configured", + new Object[] { n }); } } diff --git a/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java b/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java index a092bf48a..67bdc9dff 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java +++ b/src/java/org/apache/commons/math/stat/descriptive/SummaryStatistics.java @@ -18,6 +18,7 @@ package org.apache.commons.math.stat.descriptive; import java.io.Serializable; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.moment.GeometricMean; import org.apache.commons.math.stat.descriptive.moment.Mean; import org.apache.commons.math.stat.descriptive.moment.SecondMoment; @@ -599,7 +600,8 @@ public class SummaryStatistics implements StatisticalSummary, Serializable { */ private void checkEmpty() { if (n > 0) { - throw new IllegalStateException("Implementations must be configured before values are added."); + throw MathRuntimeException.createIllegalStateException("{0} values have been added before statistic is configured", + new Object[] { n }); } } diff --git a/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java b/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java index 2f0d58b3a..c1d0be51e 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java +++ b/src/java/org/apache/commons/math/stat/descriptive/moment/GeometricMean.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.stat.descriptive.moment; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.StorelessUnivariateStatistic; import org.apache.commons.math.stat.descriptive.summary.SumOfLogs; @@ -152,8 +153,8 @@ public class GeometricMean extends AbstractStorelessUnivariateStatistic { */ private void checkEmpty() { if (getN() > 0) { - throw new IllegalStateException( - "Implementation must be configured before values are added."); + throw MathRuntimeException.createIllegalStateException("{0} values have been added before statistic is configured", + new Object[] { getN() }); } } diff --git a/src/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java b/src/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java index f3aa1015a..52ba15b8d 100644 --- a/src/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java +++ b/src/java/org/apache/commons/math/stat/descriptive/moment/Kurtosis.java @@ -16,6 +16,7 @@ */ package org.apache.commons.math.stat.descriptive.moment; +import org.apache.commons.math.MathRuntimeException; import org.apache.commons.math.stat.descriptive.AbstractStorelessUnivariateStatistic; /** @@ -79,8 +80,9 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic { if (incMoment) { moment.increment(d); } else { - throw new IllegalStateException - ("Statistics constructed from external moments cannot be incremented"); + throw MathRuntimeException.createIllegalStateException("statistics constructed from external " + + "moments cannot be incremented", + null); } } @@ -111,8 +113,9 @@ public class Kurtosis extends AbstractStorelessUnivariateStatistic { if (incMoment) { moment.clear(); } else { - throw new IllegalStateException - ("Statistics constructed from external moments cannot be cleared"); + throw MathRuntimeException.createIllegalStateException("statistics constructed from external " + + "moments cannot be cleared", + null); } }