commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r506576 - in /jakarta/commons/proper/math/trunk/src: java/org/apache/commons/math/ test/org/apache/commons/math/ test/org/apache/commons/math/analysis/
Date Mon, 12 Feb 2007 18:54:25 GMT
Author: luc
Date: Mon Feb 12 10:54:24 2007
New Revision: 506576

URL: http://svn.apache.org/viewvc?view=rev&rev=506576
Log:
- refactored top level of Exception hierarchy,
- added getPatern(), getArguments() and getMessage(Locale)
  (names chosen for consistency with java.text.MessageFormat)
- deprecated some raw constructors as the top level exception are too
  coarse grained and intended only as base classes for easier to use classes
- added several constructors for use by more fine grained derived classes

Added:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
  (with props)
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ConvergenceExceptionTest.java
  (with props)
Removed:
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/analysis/ConvergenceExceptionTest.java
Modified:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ConvergenceException.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/FunctionEvaluationException.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathConfigurationException.java
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java
    jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathExceptionTest.java

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ConvergenceException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ConvergenceException.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ConvergenceException.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/ConvergenceException.java
Mon Feb 12 10:54:24 2007
@@ -27,27 +27,39 @@
 public class ConvergenceException extends MathException implements Serializable{
     
     /** Serializable version identifier */
-    private static final long serialVersionUID = -3657394299929217890L;
-    
+    private static final long serialVersionUID = 7426445244781020663L;
+
     /**
      * Default constructor.
      */
     public ConvergenceException() {
-        this(null, null);
+        super("Convergence failed", new Object[0]);
     }
     
     /**
      * Construct an exception with the given message.
-     * @param message descriptive error message. 
+     * @param message descriptive error message
+     * @deprecated as of 1.2, replaced by {@link #ConvergenceException(String, Object[])}
      */
     public ConvergenceException(String message) {
-        this(message, null);
+        super(message);
+    }
+
+    /**
+     * Constructs an exception with specified formatted detail message.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     */
+    public ConvergenceException(String pattern, Object[] arguments) {
+        super(pattern, arguments);
     }
 
     /**
      * Construct an exception with the given message and root cause.
-     * @param message descriptive error message.
-     * @param cause root cause.
+     * @param message descriptive error message
+     * @param cause  the exception or error that caused this exception to be thrown
+     * @deprecated as of 1.2, replaced by {@link #ConvergenceException(String, Object[],
Throwable)}
      */
     public ConvergenceException(String message, Throwable cause) {
         super(message, cause);
@@ -55,9 +67,21 @@
 
     /**
      * Create an exception with a given root cause.
-     * @param throwable caught exception causing this problem
+     * @param cause  the exception or error that caused this exception to be thrown
      */
-    public ConvergenceException(Throwable throwable) {
-        this(null, throwable);
+    public ConvergenceException(Throwable cause) {
+        super(cause);
     }
+
+    /**
+     * Constructs an exception with specified formatted detail message and root cause.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param cause  the exception or error that caused this exception to be thrown
+     */
+    public ConvergenceException(String pattern, Object[] arguments, Throwable cause) {
+        super(pattern, arguments, cause);
+    }
+
 }

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/FunctionEvaluationException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/FunctionEvaluationException.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/FunctionEvaluationException.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/FunctionEvaluationException.java
Mon Feb 12 10:54:24 2007
@@ -26,51 +26,79 @@
  */
 public class FunctionEvaluationException extends MathException  {
     
-    /** Serializable version identifier */
-    private static final long serialVersionUID = -317289374378977972L;
-    
+    /** Serializable version identifier. */
+    private static final long serialVersionUID = -7619974756160279127L;
+
     /** Argument causing function evaluation failure */
     private double argument = Double.NaN;
     
     /**
      * Construct an exception indicating the argument value
-     * that caused the function evaluation to fail.  Generates an exception
-     * message of the form "Evaluation failed for argument = " + argument.
+     * that caused the function evaluation to fail.
      * 
      * @param argument  the failing function argument 
      */
     public FunctionEvaluationException(double argument) {
-        this(argument, "Evaluation failed for argument = " + argument);
+        super("Evaluation failed for argument = {0}",
+              new Object[] { new Double(argument) });
+        this.argument = argument;
     }
     
     /**
      * Construct an exception using the given argument and message
-     * text.  The message text of the exception will start with 
-     * <code>message</code> and be followed by 
-     * " Evaluation failed for argument = " + argument.
+     * text.
      * 
      * @param argument  the failing function argument 
      * @param message  the exception message text
+     * @deprecated as of 1.2, replaced by {@link #FunctionEvaluationException(double, String,
Object[])
      */
     public FunctionEvaluationException(double argument, String message) {
-        this(argument, message, null);
+        super(message);
+        this.argument = argument;
+    }
+
+    /**
+     * Constructs an exception with specified formatted detail message.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param argument  the failing function argument 
+     * @param pattern format specifier
+     * @param arguments format arguments
+     */
+    public FunctionEvaluationException(double argument,
+                                       String pattern, Object[] arguments) {
+        super(pattern, arguments);
+        this.argument = argument;
     }
 
     /**
      * Construct an exception with the given argument, message and root cause.
-     * The message text of the exception will start with  <code>message</code>
-     * and be followed by " Evaluation failed for argument = " + argument.
      * 
      * @param argument  the failing function argument 
      * @param message descriptive error message
      * @param cause root cause.
+     * @deprecated as of 1.2, replaced by {@link #FunctionEvaluationException(double, String,
Object[], Throwable)}
      */
-    public FunctionEvaluationException(double argument, String message, 
-            Throwable cause) {
-        super(message + " Evaluation failed for argument=" + argument, cause);
+    public FunctionEvaluationException(double argument,
+                                       String message, Throwable cause) {
+        super(message, cause);
         this.argument = argument;
     }
-    
+
+    /**
+     * Constructs an exception with specified formatted detail message and root cause.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param argument  the failing function argument 
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param cause  the exception or error that caused this exception to be thrown
+     */
+    public FunctionEvaluationException(double argument,
+                                       String pattern, Object[] arguments,
+                                       Throwable cause) {
+        super(pattern, arguments, cause);
+        this.argument = argument;
+    }
+
     /**
      * Returns the function argument that caused this exception.
      * 
@@ -79,4 +107,5 @@
     public double getArgument() {
         return this.argument;
     }
+
 }

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathConfigurationException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathConfigurationException.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathConfigurationException.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathConfigurationException.java
Mon Feb 12 10:54:24 2007
@@ -22,42 +22,63 @@
  * Signals a configuration problem with any of the factory methods.
  * @version $Revision$ $Date$
  */
-public class MathConfigurationException extends MathException implements Serializable {
-    
-    /** Serializable version identifier */
-    private static final long serialVersionUID = -7958299004965931723L;
+public class MathConfigurationException extends MathException implements Serializable{
 
+    /** Serializable version identifier */
+    private static final long serialVersionUID = -4056541384141349722L;
     /**
      * Default constructor.
      */
     public MathConfigurationException() {
-        this(null, null);
+        super();
     }
-
+    
     /**
      * Construct an exception with the given message.
-     * @param message message describing the problem
+     * @param message descriptive error message
+     * @deprecated as of 1.2, replaced by {@link #MathConfigurationException(String, Object[])}
+     */
+    public MathConfigurationException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs an exception with specified formatted detail message.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
      */
-    public MathConfigurationException(final String message) {
-        this(message, null);
+    public MathConfigurationException(String pattern, Object[] arguments) {
+        super(pattern, arguments);
     }
 
     /**
      * Construct an exception with the given message and root cause.
-     * @param message message describing the problem
-     * @param throwable caught exception causing this problem
+     * @param message descriptive error message
+     * @param cause  the exception or error that caused this exception to be thrown
+     * @deprecated as of 1.2, replaced by {@link #MathConfigurationException(String, Object[],
Throwable)}
      */
-    public MathConfigurationException(
-        final String message,
-        final Throwable throwable) {
-        super(message, throwable);
+    public MathConfigurationException(String message, Throwable cause) {
+        super(message, cause);
     }
 
     /**
-     * Construct an exception with the given root cause.
-     * @param throwable caught exception causing this problem
+     * Create an exception with a given root cause.
+     * @param cause  the exception or error that caused this exception to be thrown
      */
-    public MathConfigurationException(final Throwable throwable) {
-        this(null, throwable);
+    public MathConfigurationException(Throwable cause) {
+        super(cause);
     }
+
+    /**
+     * Constructs an exception with specified formatted detail message and root cause.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param cause  the exception or error that caused this exception to be thrown
+     */
+    public MathConfigurationException(String pattern, Object[] arguments, Throwable cause)
{
+        super(pattern, arguments, cause);
+    }
+
 }

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
Mon Feb 12 10:54:24 2007
@@ -18,6 +18,10 @@
 
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.text.MessageFormat;
+import java.util.Locale;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
 
 
 /**
@@ -32,8 +36,8 @@
 public class MathException extends Exception {
     
     /** Serializable version identifier */
-    private static final long serialVersionUID = -8594613561393443827L;
-    
+    private static final long serialVersionUID = -8602234299177097102L;
+
     /**
      * Does JDK support nested exceptions?
      */
@@ -49,18 +53,62 @@
         }
         JDK_SUPPORTS_NESTED = flag;
     }
-    
+
+    private static ResourceBundle cachedResources = null;
+ 
+    /**
+     * Pattern used to build the message.
+     */
+    private final String pattern;
+
+    /**
+     * Arguments used to build the message.
+     */
+    private final Object[] arguments;
+
     /**
      * Root cause of the exception
      */
     private final Throwable rootCause;
     
     /**
+     * Translate a string to a given locale.
+     * @param s string to translate
+     * @param locale locale into which to translate the string
+     * @return translated string or original string
+     * for unsupported locales or unknown strings
+     */
+    private static String translate(String s, Locale locale) {
+        try {
+            if ((cachedResources == null) || (! cachedResources.getLocale().equals(locale)))
{
+                // caching the resource bundle
+                cachedResources =
+                    ResourceBundle.getBundle("org.apache.commons.math.MessagesResources",
locale);
+            }
+
+            if (cachedResources.getLocale().equals(locale)) {
+                // the value of the resource is the translated string
+                return cachedResources.getString(s);
+            }
+            
+        } catch (MissingResourceException mre) {
+            // do nothing here
+        }
+
+        // the locale is not supported or the resource is unknown
+        // don't translate and fall back to using the string as is
+        return s;
+
+    }
+
+    /**
      * Constructs a new <code>MathException</code> with no
      * detail message.
      */
     public MathException() {
         super();
+        this.pattern   = null;
+        this.arguments = new Object[0];
         this.rootCause = null;
     }
     
@@ -69,12 +117,29 @@
      * detail message.
      *
      * @param msg  the error message.
+     * @deprecated as of 1.2, replaced by {@link #MathException(String, Object[])}
      */
     public MathException(String msg) {
         super(msg);
+        this.pattern   = msg;
+        this.arguments = new Object[0];
         this.rootCause = null;
     }
-    
+
+    /**
+     * Constructs a new <code>MathException</code> with specified
+     * formatted detail message.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     */
+    public MathException(String pattern, Object[] arguments) {
+      super(new MessageFormat(pattern, Locale.US).format(arguments));
+      this.pattern   = pattern;
+      this.arguments = arguments;
+      this.rootCause = null;
+    }
+
     /**
      * Constructs a new <code>MathException</code> with specified
      * nested <code>Throwable</code> root cause.
@@ -84,6 +149,8 @@
      */
     public MathException(Throwable rootCause) {
         super((rootCause == null ? null : rootCause.getMessage()));
+        this.pattern   = getMessage();
+        this.arguments = new Object[0];
         this.rootCause = rootCause;
     }
     
@@ -94,12 +161,60 @@
      * @param msg  the error message.
      * @param rootCause  the exception or error that caused this exception
      *                   to be thrown.
+     * @deprecated as of 1.2, replaced by {@link #MathException(String, Object[], Throwable)}
      */
     public MathException(String msg, Throwable rootCause) {
         super(msg);
+        this.pattern   = msg;
+        this.arguments = new Object[0];
         this.rootCause = rootCause;
     }
-    
+
+    /**
+     * Constructs a new <code>MathException</code> with specified
+     * formatted detail message and nested <code>Throwable</code> root cause.
+     * Message formatting is delegated to {@link java.text.MessageFormat}.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param rootCause  the exception or error that caused this exception
+     *                   to be thrown.
+     */
+    public MathException(String pattern, Object[] arguments, Throwable rootCause) {
+      super(new MessageFormat(pattern, Locale.US).format(arguments));
+      this.pattern   = pattern;
+      this.arguments = arguments;
+      this.rootCause = rootCause;
+    }
+
+    /** Gets the pattern used to build the message of this throwable.
+     *
+     * @return the pattern used to build the message of this throwable
+     */
+    public String getPattern() {
+        return pattern;
+    }
+
+    /** Gets the arguments used to build the message of this throwable.
+     *
+     * @return the arguments used to build the message of this throwable
+     */
+    public Object[] getArguments() {
+        return arguments;
+    }
+
+    /** Gets the message in a specified locale.
+     *
+     * @param locale Locale in which the message should be translated
+     * 
+     * @return localized message
+     */
+    public String getMessage(Locale locale) {
+        if (pattern == null) {
+            return null;
+        }
+        return new MessageFormat(translate(pattern, locale), locale).format(arguments);
+    }
+
     /**
      * Gets the cause of this throwable.
      * 

Added: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java?view=auto&rev=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
(added)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
Mon Feb 12 10:54:24 2007
@@ -0,0 +1,130 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+// 
+//   http://www.apache.org/licenses/LICENSE-2.0
+// 
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.commons.math;
+
+import java.util.ListResourceBundle;
+
+/** French localization message resources for the commons-math library.
+ * @version $Revision:$
+ */
+public class MessagesResources_fr
+  extends ListResourceBundle {
+
+  /** Simple constructor.
+   */
+  public MessagesResources_fr() {
+  }
+
+  public Object[][] getContents() {
+    return (Object[][]) contents.clone();
+  }
+
+  static final Object[][] contents = {
+
+    // org.apache.commons.math.FunctionEvaluationException
+    { "Evaluation failed for argument = {0}",
+      "Erreur d''\u00e9valuation pour l''argument {0}" },
+
+    // org.apache.commons.math.DuplicateSampleAbscissaException
+    { "Abscissa {0} is duplicated at both indices {1} and {2}",
+      "Abscisse {0} dupliqu\u00e9e aux indices {1} et {2}" },
+
+    // org.apache.commons.math.ConvergenceException
+    { "Convergence failed",
+      "\u00c9chec de convergence" },
+
+    // org.apache.commons.math.ArgumentOutsideDomainException
+    { "Argument {0} outside domain [{1} ; {2}]",
+      "Argument {0} hors du domaine [{1} ; {2}]" },
+
+    // org.apache.commons.math.MaxIterationsExceededException
+    { "Maximal number of iterations ({0}) exceeded",
+      "Nombre maximal d''it\u00e9rations ({0}) d\u00e9pass\u00e9" },
+
+    // org.apache.commons.math.fraction.FractionConversionException
+    { "Unable to convert {0} to fraction after {1} iterations",
+      "Impossible de convertir {0} en fraction apr\u00e8s {1} it\u00e9rations" },
+
+    // org.apache.commons.math.analysis.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}" },
+
+    // org.apache.commons.math.util.ContinuedFraction
+    { "Continued fraction convergents diverged to +/- infinity for value {0}",
+      "Divergence de fraction continue \u00e0 l''infini pour la valeur {0}" },
+    { "Continued fraction convergents failed to converge for value {0}",
+      "\u00c9chec de convergence de fraction continue pour la valeur {0}" },
+
+    // org.apache.commons.math.util.DefaultTransformer
+    { "Conversion Exception in Transformation, Object is null",
+      "Exception de conversion dans une transformation, l''objet est nul" },
+    { "Conversion Exception in Transformation: {0}",
+      "Exception de conversion dans une transformation : {0}" },
+
+    // org.apache.commons.math.estimation.GaussNewtonEstimator
+    { "unable to converge in {0} iterations",
+      "pas de convergence apr\u00e8s {0} it\u00e9rations" },
+
+    // org.apache.commons.math.estimation.LevenbergMarquardtEstimator
+    { "cost relative tolerance is too small ({0}), no further reduction in the sum of squares
is possible",
+      "trop petite tol\u00e9rance relative sur le co\u00fbt ({0}), aucune r\u00e9duction
de la somme des carr\u00e9s n''est possible" },
+    { "parameters relative tolerance is too small ({0}), no further improvement in the approximate
solution is possible",
+      "trop petite tol\u00e9rance relative sur les param\u00e8tres ({0}), aucune am\u00e9lioration
de la solution approximative n''est possible" },
+    { "orthogonality tolerance is too small ({0}), solution is orthogonal to the jacobian",
+      "trop petite tol\u00e9rance sur l''orthogonalit\u00e9 ({0}), la solution est orthogonale
\u00e0 la jacobienne" },
+    { "maximal number of evaluations exceeded ({0})",
+      "nombre maximal d''\u00e9valuations d\u00e9pass\u00e9 ({0})" },
+
+    // org.apache.commons.math.geometry.CardanEulerSingularityException
+    { "Cardan angles singularity",
+      "singularit\u00e9 d''angles de Cardan" },
+    { "Euler angles singularity",
+      "singularit\u00e9 d''angles d''Euler" },
+
+    // org.apache.commons.math.geometry.Rotation
+    { "a {0}x{1} matrix cannot be a rotation matrix",
+      "une matrice {0}x{1} ne peut pas \u00e9tre une matrice de rotation" },
+    { "the closest orthogonal matrix has a negative determinant {0}",
+      "la matrice orthogonale la plus proche a un d\u00e9terminant n\u00e9gatif {0}" },
+    { "unable to orthogonalize matrix in {0} iterations",
+      "impossible de rendre la matrice orthogonale en {0} it\u00e9rations" },
+
+    // org.apache.commons.math.ode.AdaptiveStepsizeIntegrator
+    { "minimal step size ({0}) reached, integration needs {1}",
+      "pas minimal ({0}) atteint, l''int\u00e9gration n\u00e9cessite {1}" },
+
+    // org.apache.commons.math.ode.GraggBulirschStoerIntegrator,
+    // org.apache.commons.math.ode.RungeKuttaFehlbergIntegrator,
+    // org.apache.commons.math.ode.RungeKuttaIntegrator
+    { "dimensions mismatch: ODE problem has dimension {0},"
+    + " state vector has dimension {1}",
+      "incompatibilit\u00e9 de dimensions entre le probl\u00e8me ODE ({0}),"
+    + " et le vecteur d''\u00e9tat ({1})" },
+    { "too small integration interval: length = {0}",
+      "intervalle d''int\u00e9gration trop petit : {0}" },
+
+    // org.apache.commons.math.optimization.DirectSearchOptimizer
+    { "none of the {0} start points lead to convergence",
+      "aucun des {0} points de d\u00e9part n''aboutit \u00e0 une convergence"  }
+
+  };
+
+}

Propchange: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MessagesResources_fr.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ConvergenceExceptionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ConvergenceExceptionTest.java?view=auto&rev=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ConvergenceExceptionTest.java
(added)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ConvergenceExceptionTest.java
Mon Feb 12 10:54:24 2007
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ * 
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.math;
+
+import junit.framework.TestCase;
+
+import java.util.Locale;
+
+/**
+ * @version $Revision: 480442 $ $Date: 2006-11-29 08:21:22 +0100 (mer., 29 nov. 2006) $
+ */
+public class ConvergenceExceptionTest extends TestCase {
+
+    public void testConstructor(){
+        ConvergenceException ex = new ConvergenceException();
+        assertNull(ex.getCause());
+        assertNotNull(ex.getMessage());
+        assertNotNull(ex.getMessage(Locale.FRENCH));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
+    }
+    
+    public void testConstructorPatternArguments(){
+        String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
+        Object[] arguments = { new Integer(6), new Integer(4) };
+        ConvergenceException ex = new ConvergenceException(pattern, arguments);
+        assertNull(ex.getCause());
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
+    }
+    
+    public void testConstructorCause(){
+        String inMsg = "inner message";
+        Exception cause = new Exception(inMsg);
+        ConvergenceException ex = new ConvergenceException(cause);
+        assertEquals(cause, ex.getCause());
+    }
+
+    public void testConstructorPatternArgumentsCause(){
+        String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
+        Object[] arguments = { new Integer(6), new Integer(4) };
+        String inMsg = "inner message";
+        Exception cause = new Exception(inMsg);
+        ConvergenceException ex = new ConvergenceException(pattern, arguments, cause);
+        assertEquals(cause, ex.getCause());
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
+    }
+    
+}

Propchange: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/ConvergenceExceptionTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java
(original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/FunctionEvaluationExceptionTest.java
Mon Feb 12 10:54:24 2007
@@ -17,6 +17,8 @@
 
 package org.apache.commons.math;
 
+import java.util.Locale;
+
 import junit.framework.TestCase;
 
 /**
@@ -28,26 +30,38 @@
         FunctionEvaluationException ex = new FunctionEvaluationException(0.0);
         assertNull(ex.getCause());
         assertNotNull(ex.getMessage());
+        assertTrue(ex.getMessage().indexOf("0") > 0);
         assertEquals(0.0, ex.getArgument(), 0);
     }
     
-    public void testConstructorMessage(){
-        String msg = "message";
-        FunctionEvaluationException  ex = new FunctionEvaluationException(0.0, msg);
+    public void testConstructorPatternArguments(){
+        String pattern = "Evaluation failed for argument = {0}";
+        Object[] arguments = { new Double(0.0) };
+        FunctionEvaluationException ex = new FunctionEvaluationException(0.0, pattern, arguments);
         assertNull(ex.getCause());
-        assertTrue(ex.getMessage().startsWith(msg));
-        assertTrue(ex.getMessage().indexOf("0") > 0);
-        assertEquals(0.0, ex.getArgument(), 0);
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
-    
-    public void testConstructorMessageCause(){
-        String outMsg = "outer message";
+
+    public void testConstructorPatternArgumentsCause(){
+        String pattern = "Evaluation failed for argument = {0}";
+        Object[] arguments = { new Double(0.0) };
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
-        FunctionEvaluationException ex = new FunctionEvaluationException(0, outMsg, cause);
-        assertTrue(ex.getMessage().startsWith(outMsg));
-        assertTrue(ex.getMessage().indexOf("0") > 0);
+        FunctionEvaluationException ex = new FunctionEvaluationException(0.0, pattern, arguments,
cause);
         assertEquals(cause, ex.getCause());
-        assertEquals(0.0, ex.getArgument(), 0);
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
+
 }

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java
(original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathConfigurationExceptionTest.java
Mon Feb 12 10:54:24 2007
@@ -19,48 +19,55 @@
 
 import junit.framework.TestCase;
 
+import java.util.Locale;
+
 /**
  * @version $Revision$ $Date$
  */
 public class MathConfigurationExceptionTest extends TestCase {
-    /**
-     * 
-     */
+
     public void testConstructor(){
         MathConfigurationException ex = new MathConfigurationException();
         assertNull(ex.getCause());
         assertNull(ex.getMessage());
+        assertNull(ex.getMessage(Locale.FRENCH));
     }
     
-    /**
-     * 
-     */
-    public void testConstructorMessage(){
-        String msg = "message";
-        MathConfigurationException ex = new MathConfigurationException(msg);
+    public void testConstructorPatternArguments(){
+        String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
+        Object[] arguments = { new Integer(6), new Integer(4) };
+        MathConfigurationException ex = new MathConfigurationException(pattern, arguments);
         assertNull(ex.getCause());
-        assertEquals(msg, ex.getMessage());
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
     
-    /**
-     * 
-     */
-    public void testConstructorMessageCause(){
-        String outMsg = "outer message";
+    public void testConstructorCause(){
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
-        MathConfigurationException ex = new MathConfigurationException(outMsg, cause);
-        assertEquals(outMsg, ex.getMessage());
+        MathConfigurationException ex = new MathConfigurationException(cause);
         assertEquals(cause, ex.getCause());
     }
-    
-    /**
-     * 
-     */
-    public void testConstructorCause(){
+
+    public void testConstructorPatternArgumentsCause(){
+        String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
+        Object[] arguments = { new Integer(6), new Integer(4) };
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
-        MathConfigurationException ex = new MathConfigurationException(cause);
+        MathConfigurationException ex = new MathConfigurationException(pattern, arguments,
cause);
         assertEquals(cause, ex.getCause());
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
+    
 }

Modified: jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathExceptionTest.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathExceptionTest.java?view=diff&rev=506576&r1=506575&r2=506576
==============================================================================
--- jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathExceptionTest.java
(original)
+++ jakarta/commons/proper/math/trunk/src/test/org/apache/commons/math/MathExceptionTest.java
Mon Feb 12 10:54:24 2007
@@ -22,50 +22,55 @@
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
 import java.io.PrintWriter;
+import java.util.Locale;
 
 /**
  * @version $Revision$ $Date$
  */
 public class MathExceptionTest extends TestCase {
-    /**
-     * 
-     */
+
     public void testConstructor(){
         MathException ex = new MathException();
         assertNull(ex.getCause());
         assertNull(ex.getMessage());
+        assertNull(ex.getMessage(Locale.FRENCH));
     }
     
-    /**
-     * 
-     */
-    public void testConstructorMessage(){
-        String msg = "message";
-        MathException ex = new MathException(msg);
+    public void testConstructorPatternArguments(){
+        String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
+        Object[] arguments = { new Integer(6), new Integer(4) };
+        MathException ex = new MathException(pattern, arguments);
         assertNull(ex.getCause());
-        assertEquals(msg, ex.getMessage());
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
     
-    /**
-     * 
-     */
-    public void testConstructorMessageCause(){
-        String outMsg = "outer message";
+    public void testConstructorCause(){
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
-        MathException ex = new MathException(outMsg, cause);
-        assertEquals(outMsg, ex.getMessage());
+        MathException ex = new MathException(cause);
         assertEquals(cause, ex.getCause());
     }
-    
-    /**
-     * 
-     */
-    public void testConstructorCause(){
+
+    public void testConstructorPatternArgumentsCause(){
+        String pattern = "a {0}x{1} matrix cannot be a rotation matrix";
+        Object[] arguments = { new Integer(6), new Integer(4) };
         String inMsg = "inner message";
         Exception cause = new Exception(inMsg);
-        MathException ex = new MathException(cause);
+        MathException ex = new MathException(pattern, arguments, cause);
         assertEquals(cause, ex.getCause());
+        assertEquals(pattern, ex.getPattern());
+        assertEquals(arguments.length, ex.getArguments().length);
+        for (int i = 0; i < arguments.length; ++i) {
+            assertEquals(arguments[i], ex.getArguments()[i]);
+        }
+        assertFalse(pattern.equals(ex.getMessage()));
+        assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
     
     /**
@@ -74,8 +79,8 @@
     public void testPrintStackTrace() {
         String outMsg = "outer message";
         String inMsg = "inner message";
-        MathException cause = new MathConfigurationException(inMsg);
-        MathException ex = new MathException(outMsg, cause);
+        MathException cause = new MathConfigurationException(inMsg, new Object[0]);
+        MathException ex = new MathException(outMsg, new Object[0], cause);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PrintStream ps = new PrintStream(baos);
         ex.printStackTrace(ps);
@@ -99,19 +104,17 @@
     public void testSerialization() {
         String outMsg = "outer message";
         String inMsg = "inner message";
-        MathException cause = new MathConfigurationException(inMsg);
-        MathException ex = new MathException(outMsg, cause);
+        MathException cause = new MathConfigurationException(inMsg, new Object[0]);
+        MathException ex = new MathException(outMsg, new Object[0], cause);
         MathException image = (MathException) TestUtils.serializeAndRecover(ex);
         
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         PrintStream ps = new PrintStream(baos);
-        PrintWriter pw = new PrintWriter(ps, true);
         ex.printStackTrace(ps);
         String stack = baos.toString();
         
         ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
         PrintStream ps2 = new PrintStream(baos2);
-        PrintWriter pw2 = new PrintWriter(ps2, true);
         image.printStackTrace(ps2);
         String stack2 = baos2.toString();
         



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message