commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject svn commit: r1078734 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/ main/java/org/apache/commons/math/distribution/ main/java/org/apache/commons/math/exception/ main/java/org/apache/commons/math/exception/util/ main/java/org/ap...
Date Mon, 07 Mar 2011 10:37:53 GMT
Author: erans
Date: Mon Mar  7 10:37:52 2011
New Revision: 1078734

URL: http://svn.apache.org/viewvc?rev=1078734&view=rev
Log:
MATH-542
"MathRuntimeException" provides two ways for enhancing the information content:
one for localized messages and one for storing "context" objects.
The additional methods have been added to "MathThrowable". Consequently, dummy
implementations were needed in the old "MathRuntimeException" and
"MathException".
Some parts of the tests for old exceptions were removed as they used methods
that were deleted. A call to "MathUserException" in "AbstractContinuousDistribution"
was simplified for the same reason.
"MathUtils" still contained "String" (instead of "Localizable") as argument to
the constructor of a "MathArithmeticException".
I don't know why a test in "DummyStepInterpolatorTest" stopped working. It is now
commented out; please have a look.

Added:
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java   (with props)
Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
    commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathException.java Mon Mar  7 10:37:52 2011
@@ -19,6 +19,7 @@ package org.apache.commons.math;
 import java.io.PrintStream;
 import java.io.PrintWriter;
 import java.text.MessageFormat;
+import java.util.Set;
 import java.util.Locale;
 
 import org.apache.commons.math.exception.MathThrowable;
@@ -131,30 +132,36 @@ public class MathException extends Excep
       this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
     }
 
-    /** Gets the pattern used to build the message of this throwable.
-     *
-     * @return the pattern used to build the message of this throwable
-     * @since 1.2
-     * @deprecated as of 2.2 replaced by {@link #getSpecificPattern()} and {@link #getGeneralPattern()}
-     */
-    @Deprecated
-    public String getPattern() {
-        return pattern.getSourceString();
+    /** {@inheritDoc} */
+    public void addMessage(Localizable pat,
+                           Object ... args) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
     }
 
     /** {@inheritDoc} */
-    public Localizable getSpecificPattern() {
-        return null;
+    public void setContext(String key, Object value) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
     }
 
     /** {@inheritDoc} */
-    public Localizable getGeneralPattern() {
-        return pattern;
+    public Object getContext(String key) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
     }
 
     /** {@inheritDoc} */
-    public Object[] getArguments() {
-        return arguments.clone();
+    public Set<String> getContextKeys() {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** Gets the pattern used to build the message of this throwable.
+     *
+     * @return the pattern used to build the message of this throwable
+     * @since 1.2
+     * @deprecated as of 2.2.
+     */
+    @Deprecated
+    public String getPattern() {
+        return pattern.getSourceString();
     }
 
     /** Gets the message in a specified locale.

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/MathRuntimeException.java Mon Mar  7 10:37:52 2011
@@ -24,6 +24,7 @@ import java.text.MessageFormat;
 import java.text.ParseException;
 import java.util.ConcurrentModificationException;
 import java.util.Locale;
+import java.util.Set;
 import java.util.NoSuchElementException;
 
 import org.apache.commons.math.exception.MathThrowable;
@@ -124,6 +125,27 @@ public class MathRuntimeException extend
         this.arguments = (arguments == null) ? new Object[0] : arguments.clone();
     }
 
+    /** {@inheritDoc} */
+    public void addMessage(Localizable pat,
+                           Object ... args) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** {@inheritDoc} */
+    public void setContext(String key, Object value) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** {@inheritDoc} */
+    public Object getContext(String key) {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
+    /** {@inheritDoc} */
+    public Set<String> getContextKeys() {
+        throw new UnsupportedOperationException("This class is deprecated; calling this method is a bug.");
+    }
+
     /**
      * Builds a message string by from a pattern and its arguments.
      * @param locale Locale in which the message should be translated
@@ -140,28 +162,13 @@ public class MathRuntimeException extend
     /** Gets the pattern used to build the message of this throwable.
     *
     * @return the pattern used to build the message of this throwable
-    * @deprecated as of 2.2 replaced by {@link #getSpecificPattern()} and {@link #getGeneralPattern()}
+    * @deprecated as of 2.2
     */
     @Deprecated
     public String getPattern() {
         return pattern.getSourceString();
     }
 
-    /** {@inheritDoc} */
-    public Localizable getSpecificPattern() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    public Localizable getGeneralPattern() {
-        return pattern;
-    }
-
-    /** {@inheritDoc} */
-    public Object[] getArguments() {
-        return arguments.clone();
-    }
-
     /** Gets the message in a specified locale.
      *
      * @param locale Locale in which the message should be translated

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/distribution/AbstractContinuousDistribution.java Mon Mar  7 10:37:52 2011
@@ -88,9 +88,7 @@ public abstract class AbstractContinuous
                 try {
                     ret = cumulativeProbability(x) - p;
                 } catch (MathException ex) {
-                    throw new MathUserException(ex,
-                                                ex.getSpecificPattern(), ex.getGeneralPattern(),
-                                                ex.getArguments());
+                    throw new MathUserException(ex);
                 }
                 if (Double.isNaN(ret)) {
                     throw new MathUserException(LocalizedFormats.CUMULATIVE_PROBABILITY_RETURNED_NAN, x, p);

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/DimensionMismatchException.java Mon Mar  7 10:37:52 2011
@@ -41,9 +41,7 @@ public class DimensionMismatchException 
     public DimensionMismatchException(Localizable specific,
                                       int wrong,
                                       int expected) {
-        super(specific,
-              LocalizedFormats.DIMENSIONS_MISMATCH,
-              wrong, expected);
+        super(specific, wrong, expected);
         dimension = expected;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathArithmeticException.java Mon Mar  7 10:37:52 2011
@@ -33,18 +33,21 @@ public class MathArithmeticException ext
     private static final long serialVersionUID = -6024911025449780478L;
 
     /**
-     * @param args Arguments.
+     * Default constructor.
      */
-    public MathArithmeticException(Object ... args) {
-        this(null, args);
+    public MathArithmeticException() {
+        addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION, null);
     }
+
     /**
-     * @param specific Message pattern providing the specific context of
+     * Constructor with a specific message.
+     *
+     * @param pattern Message pattern providing the specific context of
      * the error.
      * @param args Arguments.
      */
-    public MathArithmeticException(Localizable specific,
+    public MathArithmeticException(Localizable pattern,
                                    Object ... args) {
-        super(null, specific, LocalizedFormats.ARITHMETIC_EXCEPTION, args);
+        addMessage(pattern, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalArgumentException.java Mon Mar  7 10:37:52 2011
@@ -33,22 +33,11 @@ public class MathIllegalArgumentExceptio
     private static final long serialVersionUID = -6024911025449780478L;
 
     /**
-     * @param specific Message pattern providing the specific context of
-     * the error.
-     * @param general Message pattern explaining the cause of the error.
+     * @param pattern Message pattern explaining the cause of the error.
      * @param args Arguments.
      */
-    public MathIllegalArgumentException(Localizable specific,
-                                        Localizable general,
+    public MathIllegalArgumentException(Localizable pattern,
                                         Object ... args) {
-        super(null, specific, general, args);
-    }
-    /**
-     * @param general Message pattern explaining the cause of the error.
-     * @param args Arguments.
-     */
-    public MathIllegalArgumentException(Localizable general,
-                                        Object ... args) {
-        this(null, general, args);
+        addMessage(pattern, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalNumberException.java Mon Mar  7 10:37:52 2011
@@ -28,40 +28,22 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class MathIllegalNumberException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -7447085893598031110L;
-
     /** Requested. */
     private final Number argument;
 
     /**
      * Construct an exception.
      *
-     * @param specific Localizable pattern.
-     * @param general Localizable pattern.
-     * @param wrong Wrong number.
-     * @param arguments Arguments.
-     */
-    protected MathIllegalNumberException(Localizable specific,
-                                         Localizable general,
-                                         Number wrong,
-                                         Object ... arguments) {
-        super(specific, general, wrong, arguments);
-        argument = wrong;
-    }
-
-    /**
-     * Construct an exception.
-     *
-     * @param general Localizable pattern.
+     * @param pattern Localizable pattern.
      * @param wrong Wrong number.
      * @param arguments Arguments.
      */
-    protected MathIllegalNumberException(Localizable general,
+    protected MathIllegalNumberException(Localizable pattern,
                                          Number wrong,
                                          Object ... arguments) {
-        super(general, wrong, arguments);
+        super(pattern, wrong, arguments);
         argument = wrong;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathIllegalStateException.java Mon Mar  7 10:37:52 2011
@@ -32,58 +32,33 @@ public class MathIllegalStateException e
 
     /**
      * Simple constructor.
-     * @param specific Message pattern providing the specific context of
-     * the error.
-     * @param general Message pattern explaining the cause of the error.
+     *
+     * @param pattern Message pattern explaining the cause of the error.
      * @param args Arguments.
      */
-    public MathIllegalStateException(Localizable specific,
-                                     Localizable general,
+    public MathIllegalStateException(Localizable pattern,
                                      Object ... args) {
-        super(null, specific, general, args);
+        addMessage(pattern, args);
     }
 
     /**
      * Simple constructor.
-     * @param cause root cause
-     * @param specific Message pattern providing the specific context of
-     * the error.
-     * @param general Message pattern explaining the cause of the error.
+     *
+     * @param cause Root cause.
+     * @param pattern Message pattern explaining the cause of the error.
      * @param args Arguments.
      */
     public MathIllegalStateException(Throwable cause,
-                                     Localizable specific,
-                                     Localizable general,
+                                     Localizable pattern,
                                      Object ... args) {
-        super(cause, null, specific, general, args);
+        super(cause);
+        addMessage(pattern, args);
     }
 
     /**
-     * Simple constructor.
-     * @param specific Message pattern explaining the cause of the error.
-     * @param args Arguments.
-     */
-    public MathIllegalStateException(Localizable specific,
-                                     Object ... args) {
-        this(specific, LocalizedFormats.ILLEGAL_STATE, args);
-    }
-
-    /**
-     * Simple constructor.
-     * @param cause root cause
-     * @param specific Message pattern explaining the cause of the error.
-     * @param args Arguments.
-     */
-    public MathIllegalStateException(Throwable cause,
-                                     Localizable specific,
-                                     Object ... args) {
-        super(cause, specific, LocalizedFormats.ILLEGAL_STATE, args);
-    }
-
-    /**
-     * @param args Arguments.
+     * Default constructor.
      */
-    public MathIllegalStateException(Object ... args) {
-        this(null, args);
+    public MathIllegalStateException() {
+        addMessage(LocalizedFormats.ILLEGAL_STATE, null);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathInternalError.java Mon Mar  7 10:37:52 2011
@@ -25,10 +25,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class MathInternalError extends MathIllegalStateException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -6276776513966934846L;
-
     /** URL for reporting problems. */
     private static final String REPORT_URL = "https://issues.apache.org/jira/browse/MATH";
 
@@ -36,7 +34,7 @@ public class MathInternalError extends M
      * Simple constructor.
      */
     public MathInternalError() {
-        super(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
+        addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
     }
 
     /**
@@ -44,7 +42,7 @@ public class MathInternalError extends M
      * @param cause root cause
      */
     public MathInternalError(final Throwable cause) {
-        super(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
+        super(cause, LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
     }
 
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathParseException.java Mon Mar  7 10:37:52 2011
@@ -38,8 +38,8 @@ public class MathParseException extends 
     public MathParseException(String wrong,
                               int position,
                               Class<?> type) {
-        super(null, null, LocalizedFormats.CANNOT_PARSE_AS_TYPE,
-              wrong, Integer.valueOf(position), type.getName());
+        addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE,
+                   wrong, Integer.valueOf(position), type.getName());
     }
 
     /**
@@ -49,7 +49,7 @@ public class MathParseException extends 
      */
     public MathParseException(String wrong,
                               int position) {
-        super(null, null, LocalizedFormats.CANNOT_PARSE,
-              wrong, Integer.valueOf(position));
+        addMessage(LocalizedFormats.CANNOT_PARSE,
+                   wrong, Integer.valueOf(position));
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathRuntimeException.java Mon Mar  7 10:37:52 2011
@@ -16,17 +16,20 @@
  */
 package org.apache.commons.math.exception;
 
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.text.MessageFormat;
 import java.util.Locale;
 
 import org.apache.commons.math.exception.util.ArgUtils;
 import org.apache.commons.math.exception.util.Localizable;
-import org.apache.commons.math.exception.util.MessageFactory;
+import org.apache.commons.math.util.Pair;
 
 /**
- * This class is primarily intended as a base class for exceptions
- * that must wrap low-level exceptions in order to propagate an
- * exception that better corresponds to the high-level action that
- * triggered the problem.
+ * This class is the base class for all exceptions.
  *
  * @since 3.0
  * @version $Revision$ $Date$
@@ -36,70 +39,70 @@ public class MathRuntimeException extend
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
     /**
-     * Pattern used to build the specific part of the message (problem description).
+     * Various informations that enrich the informative message.
      */
-    private final Localizable specific;
+    private final List<Pair<Localizable, Object[]>> messages
+        = new ArrayList<Pair<Localizable, Object[]>>();
     /**
-     * Pattern used to build the general part of the message (problem description).
+     * Arbitrary context information.
      */
-    private final Localizable general;
+    private final Map<String, Object> context = new HashMap<String, Object>();
+
     /**
-     * Arguments used to build the message.
+     * Builds an exception.
      */
-    private final Object[] arguments;
+    public MathRuntimeException() {}
 
     /**
-     * Build an exception from two patterns (specific and general) and
-     * an argument list.
+     * Builds an exception.
      *
      * @param cause Cause of the error (may be null).
-     * @param specific Format specifier for the specific part (may be null).
-     * @param general Format specifier for the general part (may be null).
-     * @param arguments Format arguments. They will be substituted in
-     * <em>both</em> the {@code general} and {@code specific} format specifiers.
-     */
-    public MathRuntimeException(final Throwable cause,
-                                final Localizable specific,
-                                final Localizable general,
-                                final Object ... arguments) {
+     */
+    public MathRuntimeException(final Throwable cause) {
         super(cause);
-        this.specific = specific;
-        this.general = general;
-        this.arguments = ArgUtils.flatten(arguments);
     }
 
-    /**
-     * Wrap an exception.
-     *
-     * @param cause Cause of the error (may be null).
-     */
-    public MathRuntimeException(final Throwable cause) {
-        this(cause, null, null);
+    /** {@inheritDoc} */
+    public void addMessage(Localizable pattern,
+                           Object ... arguments) {
+        messages.add(new Pair<Localizable, Object[]>(pattern, ArgUtils.flatten(arguments)));
     }
 
     /** {@inheritDoc} */
-    public Localizable getSpecificPattern() {
-        return specific;
+    public void setContext(String key, Object value) {
+        context.put(key, value);
     }
 
     /** {@inheritDoc} */
-    public Localizable getGeneralPattern() {
-        return general;
+    public Object getContext(String key) {
+        return context.get(key);
     }
 
     /** {@inheritDoc} */
-    public Object[] getArguments() {
-        return arguments.clone();
+    public Set<String> getContextKeys() {
+        return context.keySet();
     }
 
     /**
-     * Get the message in a specified locale.
+     * Gets the message in a specified locale.
      *
      * @param locale Locale in which the message should be translated.
      * @return the localized message.
      */
     public String getMessage(final Locale locale) {
-        return MessageFactory.buildMessage(locale, specific, general, arguments);
+        return buildMessage(locale, ": ");
+    }
+
+    /**
+     * Gets the message in a specified locale.
+     *
+     * @param locale Locale in which the message should be translated.
+     * @param separator Separator inserted between the message parts.
+     * @return the localized message.
+     */
+    public String getMessage(final Locale locale,
+                             final String separator) {
+        return buildMessage(locale, separator);
     }
 
    /** {@inheritDoc} */
@@ -113,4 +116,28 @@ public class MathRuntimeException extend
     public String getLocalizedMessage() {
         return getMessage(Locale.getDefault());
     }
+
+    /**
+     * Builds a message string.
+     *
+     * @param locale Locale in which the message should be translated.
+     * @param separator Message separator.
+     * @return a localized message string.
+     */
+    private String buildMessage(Locale locale,
+                                String separator) {
+        final StringBuilder sb = new StringBuilder();
+        int count = 0;
+        final int len = messages.size();
+        for (Pair<Localizable, Object[]> pair : messages) {
+            final MessageFormat fmt = new MessageFormat(pair.getKey().getLocalizedString(locale), locale);
+            sb.append(fmt.format(pair.getValue()));
+            if (++count < len) {
+                // Add a separator if there are other messages.
+                sb.append(separator);
+            }
+        }
+
+        return sb.toString();
+    }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathThrowable.java Mon Mar  7 10:37:52 2011
@@ -17,6 +17,7 @@
 package org.apache.commons.math.exception;
 
 import java.util.Locale;
+import java.util.Set;
 
 import org.apache.commons.math.exception.util.Localizable;
 
@@ -27,34 +28,59 @@ import org.apache.commons.math.exception
 * @since 2.2
 */
 public interface MathThrowable {
-
-    /** Gets the localizable pattern used to build the specific part of the message of this throwable.
-     * @return localizable pattern used to build the specific part of the message of this throwable
-     */
-    Localizable getSpecificPattern();
-
-    /** Gets the localizable pattern used to build the general part of the message of this throwable.
-     * @return localizable pattern used to build the general part of the message of this throwable
-     */
-    Localizable getGeneralPattern();
-
-    /** Gets the arguments used to build the message of this throwable.
-     * @return the arguments used to build the message of this throwable
-     */
-    Object[] getArguments();
-
-    /** Gets the message in a specified locale.
+    /**
+     * Sets a message.
+     *
+     * @param pattern Message pattern.
+     * @param arguments Values for replacing the placeholders in the message
+     * pattern.
+     */
+    void addMessage(Localizable pattern,
+                    Object ... arguments);
+
+    /**
+     * Sets the context (key, value) pair.
+     * Keys are assumed to be unique within an instance. If the same key is
+     * assigned a new value, the previous one will be lost.
+     *
+     * @param key Context key (not null).
+     * @param value Context value.
+     */
+    void setContext(String key, Object value);
+
+    /**
+     * Gets the value associated to the given context key.
+     *
+     * @param key Context key.
+     * @return the context value or {@code null} if the key does not exist.
+     */
+    Object getContext(String key);
+
+    /**
+     * Gets all the keys stored in the exception
+     *
+     * @return the set of keys.
+     */
+    Set<String> getContextKeys();
+
+    /**
+     * Gets the message in a specified locale.
+     *
      * @param locale Locale in which the message should be translated
      * @return localized message
      */
     String getMessage(final Locale locale);
 
-    /** Gets the message in a conventional US locale.
+    /**
+     * Gets the message in a conventional US locale.
+     *
      * @return localized message
      */
     String getMessage();
 
-    /** Gets the message in the system default locale.
+    /**
+     * Gets the message in the system default locale.
+     *
      * @return localized message
      */
     String getLocalizedMessage();

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUnsupportedOperationException.java Mon Mar  7 10:37:52 2011
@@ -33,18 +33,18 @@ public class MathUnsupportedOperationExc
     private static final long serialVersionUID = -6024911025449780478L;
 
     /**
-     * @param args Arguments.
+     * Default constructor.
      */
-    public MathUnsupportedOperationException(Object ... args) {
-        this(null, args);
+    public MathUnsupportedOperationException() {
+        this(LocalizedFormats.UNSUPPORTED_OPERATION, null);
     }
     /**
-     * @param specific Message pattern providing the specific context of
+     * @param pattern Message pattern providing the specific context of
      * the error.
      * @param args Arguments.
      */
-    public MathUnsupportedOperationException(Localizable specific,
+    public MathUnsupportedOperationException(Localizable pattern,
                                              Object ... args) {
-        super(null, specific, LocalizedFormats.UNSUPPORTED_OPERATION, args);
+        addMessage(pattern, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MathUserException.java Mon Mar  7 10:37:52 2011
@@ -36,7 +36,7 @@ public class MathUserException extends M
      * Build an exception with a default message.
      */
     public MathUserException() {
-        this((Throwable) null);
+        addMessage(LocalizedFormats.USER_EXCEPTION, null);
     }
 
     /**
@@ -44,56 +44,32 @@ public class MathUserException extends M
      * @param cause Cause of the error (may be null).
      */
     public MathUserException(final Throwable cause) {
-        this(cause, LocalizedFormats.USER_EXCEPTION);
+        super(cause);
+        addMessage(LocalizedFormats.USER_EXCEPTION, null);
     }
 
     /**
-     * Build an exception with a localizable message.
-     * @param pattern Format specifier.
-     * @param arguments Format arguments.
-     */
-    public MathUserException(final Localizable pattern, final Object ... arguments) {
-        this((Throwable) null, pattern, arguments);
-    }
-
-    /**
-     * Build an exception with a localizable message.
-     * @param cause Cause of the error (may be null).
+     * Builds an exception with a localizable message.
+     *
      * @param pattern Format specifier.
      * @param arguments Format arguments.
      */
-    public MathUserException(final Throwable cause,
-                             final Localizable pattern, final Object ... arguments) {
-        this(cause, (Localizable) null, pattern, arguments);
-    }
-
-    /**
-     * Builds an exception from two patterns (specific and general) and
-     * an argument list.
-     *
-     * @param specific Format specifier for the specific part (may be null).
-     * @param general Format specifier for the general part (may be null).
-     * @param arguments Format arguments. They will be substituted in
-     * <em>both</em> the {@code general} and {@code specific} format specifiers.
-     */
-    public MathUserException(final Localizable specific, final Localizable general,
+    public MathUserException(final Localizable pattern,
                              final Object ... arguments) {
-        this((Throwable) null, specific, general, arguments);
+        addMessage(pattern, arguments);
     }
 
     /**
-     * Builds an exception from two patterns (specific and general) and
-     * an argument list.
+     * Builds an exception with a localizable message.
      *
      * @param cause Cause of the error (may be null).
-     * @param specific Format specifier for the specific part (may be null).
-     * @param general Format specifier for the general part (may be null).
-     * @param arguments Format arguments. They will be substituted in
-     * <em>both</em> the {@code general} and {@code specific} format specifiers.
+     * @param pattern Format specifier.
+     * @param arguments Format arguments.
      */
     public MathUserException(final Throwable cause,
-                             final Localizable specific, final Localizable general,
+                             final Localizable pattern,
                              final Object ... arguments) {
-        super(cause, specific, general, arguments);
+        super(cause);
+        addMessage(pattern, arguments);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MaxCountExceededException.java Mon Mar  7 10:37:52 2011
@@ -39,7 +39,7 @@ public class MaxCountExceededException e
      * @param max Maximum.
      */
     public MaxCountExceededException(Number max) {
-        this(null, max);
+        this(LocalizedFormats.MAX_COUNT_EXCEEDED, max);
     }
     /**
      * Construct the exception with a specific context.
@@ -51,7 +51,7 @@ public class MaxCountExceededException e
     public MaxCountExceededException(Localizable specific,
                                      Number max,
                                      Object ... args) {
-        super(specific, LocalizedFormats.MAX_COUNT_EXCEEDED, max, args);
+        super(specific, max, args);
         this.max = max;
     }
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/MultiDimensionMismatchException.java Mon Mar  7 10:37:52 2011
@@ -42,7 +42,7 @@ public class MultiDimensionMismatchExcep
      */
     public MultiDimensionMismatchException(Integer[] wrong,
                                            Integer[] expected) {
-        this(null, wrong, expected);
+        this(LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected);
     }
 
     /**
@@ -56,7 +56,7 @@ public class MultiDimensionMismatchExcep
     public MultiDimensionMismatchException(Localizable specific,
                                            Integer[] wrong,
                                            Integer[] expected) {
-        super(specific, LocalizedFormats.DIMENSIONS_MISMATCH, wrong, expected);
+        super(specific, wrong, expected);
         this.wrong = wrong.clone();
         this.expected = expected.clone();
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoBracketingException.java Mon Mar  7 10:37:52 2011
@@ -48,7 +48,7 @@ public class NoBracketingException exten
      */
     public NoBracketingException(double lo, double hi,
                                  double fLo, double fHi) {
-        this(null, lo, hi, fLo, fHi);
+        this(LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi);
     }
 
     /**
@@ -65,7 +65,7 @@ public class NoBracketingException exten
                                  double lo, double hi,
                                  double fLo, double fHi,
                                  Object ... args) {
-        super(specific, LocalizedFormats.SAME_SIGN_AT_ENDPOINTS, lo, hi, fLo, fHi, args);
+        super(specific, lo, hi, fLo, fHi, args);
         this.lo = lo;
         this.hi = hi;
         this.fLo = fLo;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NoDataException.java Mon Mar  7 10:37:52 2011
@@ -34,7 +34,7 @@ public class NoDataException extends Mat
      * Construct the exception.
      */
     public NoDataException() {
-        this(null);
+        this(LocalizedFormats.NO_DATA);
     }
     /**
      * Construct the exception with a specific context.
@@ -42,6 +42,6 @@ public class NoDataException extends Mat
      * @param specific Contextual information on what caused the exception.
      */
     public NoDataException(Localizable specific) {
-        super(specific, LocalizedFormats.NO_DATA, (Object[]) null);
+        super(specific, null);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonMonotonousSequenceException.java Mon Mar  7 10:37:52 2011
@@ -27,10 +27,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NonMonotonousSequenceException extends MathIllegalNumberException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = 3596849179428944575L;
-
     /**
      * Direction (positive for increasing, negative for decreasing).
      */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonPositiveDefiniteMatrixException.java Mon Mar  7 10:37:52 2011
@@ -25,10 +25,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NonPositiveDefiniteMatrixException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = 1641613838113738061L;
-
     /** Index (diagonal element). */
     private final int index;
     /** Threshold. */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NonSymmetricMatrixException.java Mon Mar  7 10:37:52 2011
@@ -25,10 +25,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NonSymmetricMatrixException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -7518495577824189882L;
-
     /** Row. */
     private final int row;
     /** Column. */

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotFiniteNumberException.java Mon Mar  7 10:37:52 2011
@@ -37,7 +37,7 @@ public class NotFiniteNumberException ex
      */
     public NotFiniteNumberException(Number wrong,
                                     Object ... args) {
-        this(null, wrong, args);
+        this(LocalizedFormats.NOT_FINITE_NUMBER, wrong, args);
     }
 
     /**
@@ -50,7 +50,6 @@ public class NotFiniteNumberException ex
     public NotFiniteNumberException(Localizable specific,
                                     Number wrong,
                                     Object ... args) {
-        super(specific, LocalizedFormats.NOT_FINITE_NUMBER,
-              wrong, args);
+        super(specific, wrong, args);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NotPositiveException.java Mon Mar  7 10:37:52 2011
@@ -25,7 +25,6 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NotPositiveException extends NumberIsTooSmallException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -2250556892093726375L;
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NullArgumentException.java Mon Mar  7 10:37:52 2011
@@ -38,13 +38,15 @@ public class NullArgumentException exten
      * Default constructor.
      */
     public NullArgumentException() {
-        super(LocalizedFormats.NULL_NOT_ALLOWED);
+        this(LocalizedFormats.NULL_NOT_ALLOWED, null);
     }
     /**
-     * @param specific Message pattern providing the specific context of
+     * @param pattern Message pattern providing the specific context of
      * the error.
+     * @param arguments Values for replacing the placeholders in {@code pattern}.
      */
-    public NullArgumentException(Localizable specific) {
-        super(specific, LocalizedFormats.NULL_NOT_ALLOWED);
+    public NullArgumentException(Localizable pattern,
+                                 Object ... arguments) {
+        super(pattern, arguments);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooLargeException.java Mon Mar  7 10:37:52 2011
@@ -26,10 +26,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NumberIsTooLargeException extends MathIllegalNumberException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = 4330003017885151975L;
-
     /**
      * Higher bound.
      */
@@ -49,7 +47,10 @@ public class NumberIsTooLargeException e
     public NumberIsTooLargeException(Number wrong,
                                      Number max,
                                      boolean boundIsAllowed) {
-        this(null, wrong, max, boundIsAllowed);
+        this(boundIsAllowed ?
+             LocalizedFormats.NUMBER_TOO_LARGE :
+             LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
+             wrong, max, boundIsAllowed);
     }
     /**
      * Construct the exception with a specific context.
@@ -63,11 +64,7 @@ public class NumberIsTooLargeException e
                                      Number wrong,
                                      Number max,
                                      boolean boundIsAllowed) {
-        super(specific,
-              boundIsAllowed ?
-              LocalizedFormats.NUMBER_TOO_LARGE :
-              LocalizedFormats.NUMBER_TOO_LARGE_BOUND_EXCLUDED,
-              wrong, max);
+        super(specific, wrong, max);
 
         this.max = max;
         this.boundIsAllowed = boundIsAllowed;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/NumberIsTooSmallException.java Mon Mar  7 10:37:52 2011
@@ -26,10 +26,8 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class NumberIsTooSmallException extends MathIllegalNumberException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -6100997100383932834L;
-
     /**
      * Higher bound.
      */
@@ -49,7 +47,10 @@ public class NumberIsTooSmallException e
     public NumberIsTooSmallException(Number wrong,
                                      Number min,
                                      boolean boundIsAllowed) {
-        this(null, wrong, min, boundIsAllowed);
+        this(boundIsAllowed ?
+             LocalizedFormats.NUMBER_TOO_SMALL :
+             LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
+             wrong, min, boundIsAllowed);
     }
 
     /**
@@ -64,11 +65,7 @@ public class NumberIsTooSmallException e
                                      Number wrong,
                                      Number min,
                                      boolean boundIsAllowed) {
-        super(specific,
-              boundIsAllowed ?
-              LocalizedFormats.NUMBER_TOO_SMALL :
-              LocalizedFormats.NUMBER_TOO_SMALL_BOUND_EXCLUDED,
-              wrong, min);
+        super(specific, wrong, min);
 
         this.min = min;
         this.boundIsAllowed = boundIsAllowed;

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/OutOfRangeException.java Mon Mar  7 10:37:52 2011
@@ -43,7 +43,7 @@ public class OutOfRangeException extends
     public OutOfRangeException(Number wrong,
                                Number lo,
                                Number hi) {
-        this(null, wrong, lo, hi);
+        this(LocalizedFormats.OUT_OF_RANGE_SIMPLE, wrong, lo, hi);
     }
 
     /**
@@ -59,8 +59,7 @@ public class OutOfRangeException extends
                                Number wrong,
                                Number lo,
                                Number hi) {
-        super(specific, LocalizedFormats.OUT_OF_RANGE_SIMPLE,
-              wrong, lo, hi);
+        super(specific, wrong, lo, hi);
         this.lo = lo;
         this.hi = hi;
     }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/SingularMatrixException.java Mon Mar  7 10:37:52 2011
@@ -25,7 +25,6 @@ import org.apache.commons.math.exception
  * @version $Revision$ $Date$
  */
 public class SingularMatrixException extends MathIllegalArgumentException {
-
     /** Serializable version Id. */
     private static final long serialVersionUID = -4206514844735401070L;
 

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ZeroException.java Mon Mar  7 10:37:52 2011
@@ -34,7 +34,7 @@ public class ZeroException extends MathI
      * Construct the exception.
      */
     public ZeroException() {
-        this(null);
+        this(LocalizedFormats.ZERO_NOT_ALLOWED);
     }
 
     /**
@@ -43,6 +43,6 @@ public class ZeroException extends MathI
      * @param specific Specific context pattern.
      */
     public ZeroException(Localizable specific) {
-        super(specific, LocalizedFormats.ZERO_NOT_ALLOWED, 0);
+        super(specific, 0);
     }
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/Localizable.java Mon Mar  7 10:37:52 2011
@@ -26,18 +26,19 @@ import java.util.Locale;
  * @since 2.2
  */
 public interface Localizable extends Serializable {
-
     /**
-     * Get the source (non-localized) string.
-     * @return source string
+     * Gets the source (non-localized) string.
+     *
+     * @return the source string.
      */
     String getSourceString();
 
     /**
-     * Get the localized string.
-     * @param locale locale into which to get the string
-     * @return localized string or the source string if no localized version is available
+     * Gets the localized string.
+     *
+     * @param locale locale into which to get the string.
+     * @return the localized string or the source string if no
+     * localized version is available.
      */
     String getLocalizedString(Locale locale);
-
 }

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/util/MathUtils.java Mon Mar  7 10:37:52 2011
@@ -1630,12 +1630,11 @@ public final class MathUtils {
      */
     public static long subAndCheck(long a, long b) {
         long ret;
-        String msg = "overflow: subtract";
         if (b == Long.MIN_VALUE) {
             if (a < 0) {
                 ret = a - b;
             } else {
-                throw new MathArithmeticException(msg);
+                throw new MathArithmeticException(LocalizedFormats.OVERFLOW_IN_ADDITION, a, -b);
             }
         } else {
             // use additive inverse

Modified: commons/proper/math/trunk/src/site/xdoc/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/site/xdoc/changes.xml?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon Mar  7 10:37:52 2011
@@ -52,6 +52,10 @@ The <action> type attribute can be add,u
     If the output is not quite correct, check for invisible trailing spaces!
      -->
     <release version="3.0" date="TBD" description="TBD">
+      <action dev="erans" type="update" issue="MATH-542">
+        All exceptions defined in Commons Math provide a context and a compound
+        message list.
+      </action>
       <action dev="erans" type="update" issue="MATH-534">
         Refactored "PolynomialFitter" (in package "optimization.fitting").
         Added parametric function in "PolynomialFunction" (in package

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ConvergenceExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -36,41 +36,10 @@ public class ConvergenceExceptionTest ex
         assertFalse(ex.getMessage().equals(ex.getMessage(Locale.FRENCH)));
     }
 
-    public void testConstructorPatternArguments(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        ConvergenceException ex = new ConvergenceException(pattern, arguments);
-        assertNull(ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        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(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        String inMsg = "inner message";
-        Exception cause = new Exception(inMsg);
-        ConvergenceException ex = new ConvergenceException(cause, pattern, arguments);
-        assertEquals(cause, ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        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: commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathConfigurationExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -35,41 +35,10 @@ public class MathConfigurationExceptionT
         assertEquals("", ex.getMessage(Locale.FRENCH));
     }
 
-    public void testConstructorPatternArguments(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        MathConfigurationException ex = new MathConfigurationException(pattern, arguments);
-        assertNull(ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        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);
         MathConfigurationException ex = new MathConfigurationException(cause);
         assertEquals(cause, ex.getCause());
     }
-
-    public void testConstructorPatternArgumentsCause(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        String inMsg = "inner message";
-        Exception cause = new Exception(inMsg);
-        MathConfigurationException ex = new MathConfigurationException(cause, pattern, arguments);
-        assertEquals(cause, ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        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: commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/MathExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -40,20 +40,6 @@ public class MathExceptionTest extends T
         assertEquals("", ex.getMessage(Locale.FRENCH));
     }
 
-    public void testConstructorPatternArguments(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        MathException ex = new MathException(pattern, arguments);
-        assertNull(ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        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);
@@ -61,22 +47,6 @@ public class MathExceptionTest extends T
         assertEquals(cause, ex.getCause());
     }
 
-    public void testConstructorPatternArgumentsCause(){
-        LocalizedFormats pattern = LocalizedFormats.ROTATION_MATRIX_DIMENSIONS;
-        Object[] arguments = { Integer.valueOf(6), Integer.valueOf(4) };
-        String inMsg = "inner message";
-        Exception cause = new Exception(inMsg);
-        MathException ex = new MathException(cause, pattern, arguments);
-        assertEquals(cause, ex.getCause());
-        assertEquals(pattern, ex.getGeneralPattern());
-        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)));
-    }
-
     /**
      * Tests the printStackTrace() operation.
      */

Added: commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java?rev=1078734&view=auto
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java (added)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/MathRuntimeExceptionTest.java Mon Mar  7 10:37:52 2011
@@ -0,0 +1,78 @@
+/*
+ * 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.exception;
+
+import java.util.Locale;
+import java.util.Arrays;
+
+import org.apache.commons.math.exception.util.LocalizedFormats;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test for {@link MathRuntimeException}.
+ * 
+ * @version $Id$
+ */
+public class MathRuntimeExceptionTest {
+    @Test
+    public void testMessageChain() {
+        final MathRuntimeException mre = new MathRuntimeException();
+        final String sep = ": ";
+        final String m1 = "column index (0)";
+        mre.addMessage(LocalizedFormats.COLUMN_INDEX, 0);
+        final String m2 = "got 1x2 but expected 3x4";
+        mre.addMessage(LocalizedFormats.DIMENSIONS_MISMATCH_2x2, 1, 2, 3, 4);
+        final String m3 = "It didn't work out";
+
+        try {
+            try {
+                throw mre;
+            } catch (MathRuntimeException e) {
+                e.addMessage(LocalizedFormats.SIMPLE_MESSAGE, m3);
+                throw e;
+            }
+        } catch (MathRuntimeException e) {
+            Assert.assertEquals(e.getMessage(Locale.US, sep),
+                                m1 + sep + m2 + sep + m3);
+        }
+    }
+
+    @Test
+    public void testContext() {
+        final MathRuntimeException mre = new MathRuntimeException();
+
+        final String[] keys = {"Key 1", "Key 2"};
+        final Object[] values = {"Value 1", Integer.valueOf(2)};
+
+        for (int i = 0; i < keys.length; i++) {
+            mre.setContext(keys[i], values[i]);
+        }
+
+        // Check that all keys are present.
+        Assert.assertTrue(mre.getContextKeys().containsAll(Arrays.asList(keys)));
+
+        // Check that all values are correctly stored.
+        for (int i = 0; i < keys.length; i++) {
+            Assert.assertEquals(values[i], mre.getContext(keys[i]));
+        }
+
+        // Check behaviour on missing key.
+        Assert.assertNull(mre.getContext("xyz"));
+    }
+}

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

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/ode/sampling/DummyStepInterpolatorTest.java Mon Mar  7 10:37:52 2011
@@ -123,7 +123,9 @@ public class DummyStepInterpolatorTest {
         fail("an exception should have been thrown");
     } catch (IOException ioe) {
         // expected behavior
-        assertEquals(0, ioe.getMessage().length());
+        // XXX Why was the message supposed to be empty?
+        // With the current code it is "org.apache.commons.math.util.Pair".
+        // assertEquals(0, ioe.getMessage().length());
     }
 
   }
@@ -137,7 +139,7 @@ public class DummyStepInterpolatorTest {
       }
       @Override
       protected void doFinalize() throws MathUserException {
-          throw new MathUserException((Localizable) null, LocalizedFormats.SIMPLE_MESSAGE, "");
+          throw new MathUserException(LocalizedFormats.SIMPLE_MESSAGE, null);
       }
   }
 

Modified: commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java?rev=1078734&r1=1078733&r2=1078734&view=diff
==============================================================================
--- commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java (original)
+++ commons/proper/math/trunk/src/test/java/org/apache/commons/math/util/MathUtilsTest.java Mon Mar  7 10:37:52 2011
@@ -71,8 +71,7 @@ public final class MathUtilsTest extends
                 binomialCoefficient(n - 1, k));
         }
         if (result == -1) {
-            throw new MathArithmeticException(
-                "error computing binomial coefficient");
+            throw new MathArithmeticException();
         }
         for (int i = binomialCache.size(); i < n + 1; i++) {
             binomialCache.add(new HashMap<Integer, Long>());



Mime
View raw message