Author: luc
Date: Sun May  3 18:24:31 2009
New Revision: 771097

URL: http://svn.apache.org/viewvc?rev=771097&view=rev
Log:
improved error messages

Modified:
    
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
    
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
 Sun May  3 18:24:31 2009
@@ -71,6 +71,8 @@
     { "Maximal number of iterations ({0}) exceeded",
       "Nombre maximal d''it\u00e9rations ({0}) d\u00e9pass\u00e9" },
 
+    // org.apache.commons.math.analysis.interpolation.SplineInterpolator
+    // 
org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm
     // org.apache.commons.math.DimensionMismatchException
     // org.apache.commons.math.optimization.LeastSquaresConverter
     // org.apache.commons.math.optimization.direct.DirectSearchOptimizer
@@ -127,11 +129,34 @@
       "le format complet ne doit pas \u00eatre nul" },
 
     // org.apache.commons.math.analysis.solvers.UnivariateRealSolverUtils
-    { "Number of iterations={0}, maximum iterations={1}, initial={2}, lower 
bound={3}, upper bound={4}," +
-          " final a value={5}, final b value={6}, f(a)={7}, f(b)={8}",
-      "Nombre d''it\u00e9rations = {0}, it\u00e9rations maximum = {1}, valeur 
initiale = {2}," +
-          " borne inf\u00e9rieure = {3}, borne sup\u00e9rieure = {4}," +
-          " valeur a finale = {5}, valeur b finale = {6}, f(a) = {7}, f(b) = 
{8}" },
+    { "function is null",
+      "la fonction est nulle" },
+    { "bad value for maximum iterations number: {0}",
+      "valeur invalide pour le nombre maximal d''it\u00e9rations : {0}" },
+    { "invalid bracketing parameters:  lower bound={0},  initial={1}, upper 
bound={2}",
+      "param\u00e8tres d''encadrement invalides : borne inf\u00e9rieure = {0}, 
valeur initiale = {1}, borne sup\u00e9rieure = {2}" },
+    { "number of iterations={0}, maximum iterations={1}, initial={2}, lower 
bound={3}, upper bound={4}," +
+        " final a value={5}, final b value={6}, f(a)={7}, f(b)={8}",
+      "nombre d''it\u00e9rations = {0}, it\u00e9rations maximum = {1}, valeur 
initiale = {2}," +
+        " borne inf\u00e9rieure = {3}, borne sup\u00e9rieure = {4}," +
+        " valeur a finale = {5}, valeur b finale = {6}, f(a) = {7}, f(b) = 
{8}" },
+
+    // org.apache.commons.math.analysis.solvers.LaguerreSolver
+    { "polynomial degree must be positive: degree={0}",
+      "le polyn\u00f4me doit \u00eatre de degr\u00e9 positif : degr\u00e9 = 
{0}" },
+
+    // org.apache.commons.math.analysis.solvers.SecantSolver
+    { "function values at endpoints do not have different signs, endpoints: 
[{0}, {1}], values: [{2}, {3}]",
+      "les valeurs de la fonctions aux bornes sont de m\u00eame signe, bornes 
: [{0}, {1}], valeurs : [{2}, {3}]" },
+
+    // org.apache.commons.math.analysis.interpolation.SplineInterpolator
+    // 
org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm
+    { "{0} points are required, got only {1}",
+      "{0} sont n\u00e9cessaires, seuls {1} ont \u00e9t\u00e9 fournis" },
+
+    // org.apache.commons.math.analysis.interpolation.SplineInterpolator
+    { "points {0} and {1} are not strictly increasing ({2} >= {3})",
+      "les points {0} et {1} ne sont pas strictements croissants ({2} >= {3})" 
},
 
     // org.apache.commons.math.util.ContinuedFraction
     { "Continued fraction convergents diverged to +/- infinity for value {0}",
@@ -390,10 +415,27 @@
    { "index ({0}) is not positive",
      "l''indice ({0}) n''est pas positif" },
 
+   // org.apache.commons.math.analysis.polynomials.PolynomialFunction
+   // org.apache.commons.math.analysis.polynomials.PolynomialFunctionNewtonForm
+   { "empty polynomials coefficients array",
+     "tableau de coefficients polyn\u00f4miaux vide" },
+
+   // org.apache.commons.math.analysis.polynomials.PolynomialFunctionNewtonForm
+   { "array sizes should have difference 1 ({0} != {1} + 1)",
+     "les tableaux devraient avoir une diff\u00e9rence de taille de 1 ({0} != 
{1} + 1)" },
+
    // 
org.apache.commons.math.analysis.polynomials.PolynomialFunctionLagrangeForm
    { "identical abscissas x[{0}] == x[{1}] == {2} cause division by zero",
      "division par z\u00e9ro caus\u00e9e par les abscisses identiques x[{0}] 
== x[{1}] == {2}" },
 
+   // org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction
+   { "spline partition must have at least {0} points, got {1}",
+     "une partiction spline n\u00e9cessite au moins {0} points, seuls {1} ont 
\u00e9t\u00e9 fournis" },
+   { "knot values must be strictly increasing",
+     "les n\u0153uds d''interpolation doivent \u00eatre strictement 
croissants" },
+   { "number of polynomial interpolants must match the number of segments ({0} 
!= {1} - 1)",
+     "le nombre d''interpolants polyn\u00f4miaux doit correspondre au nombre 
de segments ({0} != {1} - 1)" },
+
    // org.apache.commons.math.analysis.solvers.UnivariateRealSolverImpl
    { "function to solve cannot be null",
      "la fonction \u00e0 r\u00e9soudre ne peux pas \u00eatre nulle" },

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/integration/UnivariateRealIntegratorImpl.java
 Sun May  3 18:24:31 2009
@@ -66,7 +66,7 @@
         throws IllegalArgumentException {
         super(defaultMaximalIterationCount, 1.0e-15);
         if (f == null) {
-            throw new IllegalArgumentException("Function can not be null.");
+            throw 
MathRuntimeException.createIllegalArgumentException("function is null");
         }
 
         this.f = f;

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/interpolation/SplineInterpolator.java
 Sun May  3 18:24:31 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.commons.math.analysis.interpolation;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import org.apache.commons.math.analysis.polynomials.PolynomialFunction;
 import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction;
@@ -57,12 +58,13 @@
      */
     public UnivariateRealFunction interpolate(double x[], double y[]) {
         if (x.length != y.length) {
-            throw new IllegalArgumentException("Dataset arrays must have same 
length.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "dimension mismatch {0} != {1}", x.length, y.length);
         }
         
         if (x.length < 3) {
-            throw new IllegalArgumentException
-                ("At least 3 datapoints are required to compute a spline 
interpolant");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "{0} points are required, got only {1}", 3, x.length);
         }
         
         // Number of intervals.  The number of data points is n + 1.
@@ -70,7 +72,9 @@
         
         for (int i = 0; i < n; i++) {
             if (x[i]  >= x[i + 1]) {
-                throw new IllegalArgumentException("Dataset x values must be 
strictly increasing.");
+                throw MathRuntimeException.createIllegalArgumentException(
+                      "points {0} and {1} are not strictly increasing ({2} >= 
{3})",
+                      i, i+1, x[i], x[i+1]);
             }
         }
         

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunction.java
 Sun May  3 18:24:31 2009
@@ -18,6 +18,7 @@
 
 import java.io.Serializable;
 
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 
@@ -58,7 +59,7 @@
     public PolynomialFunction(double c[]) {
         super();
         if (c.length < 1) {
-            throw new IllegalArgumentException("Polynomial coefficient array 
must have postive length.");
+            throw MathRuntimeException.createIllegalArgumentException("empty 
polynomials coefficients array");
         }
         int l = c.length;
         while ((l > 1) && (c[l - 1] == 0)) {
@@ -118,7 +119,7 @@
     protected static double evaluate(double[] coefficients, double argument) {
         int n = coefficients.length;
         if (n < 1) {
-            throw new IllegalArgumentException("Coefficient array must have 
positive length for evaluation");
+            throw MathRuntimeException.createIllegalArgumentException("empty 
polynomials coefficients array");
         }
         double result = coefficients[n - 1];
         for (int j = n -2; j >=0; j--) {
@@ -227,7 +228,7 @@
     protected static double[] differentiate(double[] coefficients) {
         int n = coefficients.length;
         if (n < 1) {
-            throw new IllegalArgumentException("Coefficient array must have 
positive length for differentiation");
+            throw MathRuntimeException.createIllegalArgumentException("empty 
polynomials coefficients array");
         }
         if (n == 1) {
             return new double[]{0};

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionLagrangeForm.java
 Sun May  3 18:24:31 2009
@@ -292,13 +292,14 @@
     public static void verifyInterpolationArray(double x[], double y[]) throws
         IllegalArgumentException {
 
-        if (x.length < 2 || y.length < 2) {
-            throw new IllegalArgumentException
-                ("Interpolation requires at least two points.");
+        if (Math.min(x.length, y.length) < 2) {
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "{0} points are required, got only {1}",
+                  2, Math.min(x.length, y.length));
         }
         if (x.length != y.length) {
-            throw new IllegalArgumentException
-                ("Abscissa and value arrays must have the same length.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "dimension mismatch {0} != {1}", x.length, y.length);
         }
     }
 }

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialFunctionNewtonForm.java
 Sun May  3 18:24:31 2009
@@ -18,6 +18,7 @@
 
 import java.io.Serializable;
 import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 import 
org.apache.commons.math.analysis.interpolation.DividedDifferenceInterpolator;
 
@@ -209,12 +210,13 @@
         IllegalArgumentException {
 
         if (a.length < 1 || c.length < 1) {
-            throw new IllegalArgumentException
-                ("Input arrays must not be empty.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "empty polynomials coefficients array");
         }
         if (a.length != c.length + 1) {
-            throw new IllegalArgumentException
-                ("Bad input array sizes, should have difference 1.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "array sizes should have difference 1 ({0} != {1} + 1)",
+                  a.length, c.length);
         }
     }
 }

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/polynomials/PolynomialSplineFunction.java
 Sun May  3 18:24:31 2009
@@ -20,6 +20,7 @@
 import java.util.Arrays;
 
 import org.apache.commons.math.ArgumentOutsideDomainException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.analysis.DifferentiableUnivariateRealFunction;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 
@@ -99,16 +100,18 @@
      */
     public PolynomialSplineFunction(double knots[], PolynomialFunction 
polynomials[]) {
         if (knots.length < 2) {
-            throw new IllegalArgumentException
-                ("Not enough knot values -- spline partition must have at 
least 2 points.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "spline partition must have at least {0} points, got {1}",
+                  2, knots.length);
         }
         if (knots.length - 1 != polynomials.length) {
-            throw new IllegalArgumentException 
-            ("Number of polynomial interpolants must match the number of 
segments.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "number of polynomial interpolants must match the number of 
segments ({0} != {1} - 1)",
+                  polynomials.length, knots.length);
         }
         if (!isStrictlyIncreasing(knots)) {
-            throw new IllegalArgumentException 
-                ("Knot values must be strictly increasing.");
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "knot values must be strictly increasing");
         }
         
         this.n = knots.length -1;

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/LaguerreSolver.java
 Sun May  3 18:24:31 2009
@@ -252,8 +252,8 @@
         int n = coefficients.length - 1;
         int iterationCount = 0;
         if (n < 1) {
-            throw new IllegalArgumentException
-                ("Polynomial degree must be positive: degree=" + n);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "polynomial degree must be positive: degree={0}", n);
         }
         Complex c[] = new Complex[n+1];    // coefficients for deflated 
polynomial
         for (int i = 0; i <= n; i++) {
@@ -300,8 +300,8 @@
 
         int n = coefficients.length - 1;
         if (n < 1) {
-            throw new IllegalArgumentException
-                ("Polynomial degree must be positive: degree=" + n);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "polynomial degree must be positive: degree={0}", n);
         }
         Complex N = new Complex(n, 0.0);
         Complex N1 = new Complex((n-1), 0.0);

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/SecantSolver.java
 Sun May  3 18:24:31 2009
@@ -20,6 +20,7 @@
 
 import org.apache.commons.math.ConvergenceException;
 import org.apache.commons.math.FunctionEvaluationException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.MaxIterationsExceededException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 
@@ -130,10 +131,10 @@
         
         // Verify bracketing
         if (y0 * y1 >= 0) {
-            throw new IllegalArgumentException
-            ("Function values at endpoints do not have different signs." +
-                    "  Endpoints: [" + min + "," + max + "]" + 
-                    "  Values: [" + y0 + "," + y1 + "]");       
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "function values at endpoints do not have different signs, " 
+
+                  "endpoints: [{0}, {1}], values: [{2}, {3}]",
+                  min, max, y0, y1);       
         }
         
         double x2 = x0;

Modified: 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java?rev=771097&r1=771096&r2=771097&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
 (original)
+++ 
commons/proper/math/trunk/src/java/org/apache/commons/math/analysis/solvers/UnivariateRealSolverUtils.java
 Sun May  3 18:24:31 2009
@@ -18,6 +18,7 @@
 
 import org.apache.commons.math.FunctionEvaluationException;
 import org.apache.commons.math.ConvergenceException;
+import org.apache.commons.math.MathRuntimeException;
 import org.apache.commons.math.analysis.UnivariateRealFunction;
 
 /**
@@ -167,16 +168,16 @@
             FunctionEvaluationException {
         
         if (function == null) {
-            throw new IllegalArgumentException ("function is null.");
+            throw 
MathRuntimeException.createIllegalArgumentException("function is null");
         }
         if (maximumIterations <= 0)  {
-            throw new IllegalArgumentException
-            ("bad value for maximumIterations: " + maximumIterations);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "bad value for maximum iterations number: {0}", 
maximumIterations);
         }
         if (initial < lowerBound || initial > upperBound || lowerBound >= 
upperBound) {
-            throw new IllegalArgumentException
-            ("Invalid endpoint parameters:  lowerBound=" + lowerBound + 
-              " initial=" + initial + " upperBound=" + upperBound);
+            throw MathRuntimeException.createIllegalArgumentException(
+                  "invalid bracketing parameters:  lower bound={0},  
initial={1}, upper bound={2}",
+                  lowerBound, initial, upperBound);
         }
         double a = initial;
         double b = initial;
@@ -195,9 +196,12 @@
                 ((a > lowerBound) || (b < upperBound)));
    
         if (fa * fb >= 0.0 ) {
-            throw new ConvergenceException
-            ("Number of iterations={0}, maximum iterations={1}, initial={2}, 
lower bound={3}, upper bound={4}, final a value={5}, final b value={6}, 
f(a)={7}, f(b)={8}",
-             numIterations, maximumIterations, initial, lowerBound, 
upperBound, a, b, fa, fb);
+            throw new ConvergenceException(
+                      "number of iterations={0}, maximum iterations={1}, " +
+                      "initial={2}, lower bound={3}, upper bound={4}, final a 
value={5}, " +
+                      "final b value={6}, f(a)={7}, f(b)={8}",
+                      numIterations, maximumIterations, initial,
+                      lowerBound, upperBound, a, b, fa, fb);
         }
         
         return new double[]{a, b};
@@ -221,7 +225,7 @@
      */
     private static void setup(UnivariateRealFunction f) {
         if (f == null) {
-            throw new IllegalArgumentException("function can not be null.");   
 
+            throw 
MathRuntimeException.createIllegalArgumentException("function is null");
         }
     }
 


Reply via email to