You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by er...@apache.org on 2011/05/09 15:54:34 UTC

svn commit: r1101029 - in /commons/proper/math/trunk/src: main/java/org/apache/commons/math/exception/ site/xdoc/

Author: erans
Date: Mon May  9 13:54:34 2011
New Revision: 1101029

URL: http://svn.apache.org/viewvc?rev=1101029&view=rev
Log:
MATH-566
Changed all exception classes to use the new "ExceptionContext".

Modified:
    commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ConvergenceException.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/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/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/TooManyEvaluationsException.java
    commons/proper/math/trunk/src/site/xdoc/changes.xml

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ConvergenceException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ConvergenceException.java?rev=1101029&r1=1101028&r2=1101029&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ConvergenceException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/ConvergenceException.java Mon May  9 13:54:34 2011
@@ -34,7 +34,7 @@ public class ConvergenceException extend
      * Construct the exception.
      */
     public ConvergenceException() {
-        addMessage(LocalizedFormats.CONVERGENCE_FAILED);
+        this(LocalizedFormats.CONVERGENCE_FAILED);
     }
 
     /**
@@ -46,6 +46,6 @@ public class ConvergenceException extend
      */
     public ConvergenceException(Localizable pattern,
                                 Object ... args) {
-        addMessage(pattern, args);
+        getContext().addMessage(pattern, args);
     }
 }

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -18,25 +18,30 @@ package org.apache.commons.math.exceptio
 
 import org.apache.commons.math.exception.util.Localizable;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.util.ExceptionContext;
+import org.apache.commons.math.exception.util.ExceptionContextProvider;
 
 /**
  * Base class for arithmetic exceptions.
- * It is used for all the exceptions that share the semantics of the standard
+ * It is used for all the exceptions that have the semantics of the standard
  * {@link ArithmeticException}, but must also provide a localized
  * message.
  *
  * @since 3.0
  * @version $Revision$ $Date$
  */
-public class MathArithmeticException extends MathRuntimeException {
+public class MathArithmeticException extends ArithmeticException
+    implements ExceptionContextProvider {
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
+    /** Context. */
+    private final ExceptionContext context = new ExceptionContext();
 
     /**
      * Default constructor.
      */
     public MathArithmeticException() {
-        addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION);
+        context.addMessage(LocalizedFormats.ARITHMETIC_EXCEPTION);
     }
 
     /**
@@ -48,6 +53,23 @@ public class MathArithmeticException ext
      */
     public MathArithmeticException(Localizable pattern,
                                    Object ... args) {
-        addMessage(pattern, args);
+        context.addMessage(pattern, args);
+    }
+
+    /** {@inheritDoc} */
+    public ExceptionContext getContext() {
+        return context;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getMessage() {
+        return context.getMessage();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getLocalizedMessage() {
+        return context.getLocalizedMessage();
     }
 }

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -50,7 +50,7 @@ public class MathIllegalArgumentExceptio
         return context;
     }
 
-   /** {@inheritDoc} */
+    /** {@inheritDoc} */
     @Override
     public String getMessage() {
         return context.getMessage();

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -18,6 +18,8 @@ package org.apache.commons.math.exceptio
 
 import org.apache.commons.math.exception.util.Localizable;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.util.ExceptionContext;
+import org.apache.commons.math.exception.util.ExceptionContextProvider;
 
 /**
  * Base class for all exceptions that signal a mismatch between the
@@ -26,9 +28,12 @@ import org.apache.commons.math.exception
  * @since 2.2
  * @version $Revision$ $Date$
  */
-public class MathIllegalStateException extends MathRuntimeException {
+public class MathIllegalStateException extends IllegalStateException
+    implements ExceptionContextProvider {
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
+    /** Context. */
+    private final ExceptionContext context = new ExceptionContext();
 
     /**
      * Simple constructor.
@@ -38,7 +43,7 @@ public class MathIllegalStateException e
      */
     public MathIllegalStateException(Localizable pattern,
                                      Object ... args) {
-        addMessage(pattern, args);
+        context.addMessage(pattern, args);
     }
 
     /**
@@ -52,13 +57,30 @@ public class MathIllegalStateException e
                                      Localizable pattern,
                                      Object ... args) {
         super(cause);
-        addMessage(pattern, args);
+        context.addMessage(pattern, args);
     }
 
     /**
      * Default constructor.
      */
     public MathIllegalStateException() {
-        addMessage(LocalizedFormats.ILLEGAL_STATE);
+        this(LocalizedFormats.ILLEGAL_STATE);
+    }
+
+    /** {@inheritDoc} */
+    public ExceptionContext getContext() {
+        return context;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getMessage() {
+        return context.getMessage();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getLocalizedMessage() {
+        return context.getLocalizedMessage();
     }
 }

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -34,7 +34,7 @@ public class MathInternalError extends M
      * Simple constructor.
      */
     public MathInternalError() {
-        addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
+        getContext().addMessage(LocalizedFormats.INTERNAL_ERROR, REPORT_URL);
     }
 
     /**
@@ -44,5 +44,4 @@ public class MathInternalError extends M
     public MathInternalError(final Throwable cause) {
         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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -17,6 +17,8 @@
 package org.apache.commons.math.exception;
 
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.util.ExceptionContext;
+import org.apache.commons.math.exception.util.ExceptionContextProvider;
 
 /**
  * Class to signal parse failures.
@@ -24,7 +26,8 @@ import org.apache.commons.math.exception
  * @since 2.2
  * @version $Revision$ $Date$
  */
-public class MathParseException extends MathRuntimeException {
+public class MathParseException extends MathIllegalStateException
+    implements ExceptionContextProvider {
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
 
@@ -38,8 +41,8 @@ public class MathParseException extends 
     public MathParseException(String wrong,
                               int position,
                               Class<?> type) {
-        addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE,
-                   wrong, Integer.valueOf(position), type.getName());
+        getContext().addMessage(LocalizedFormats.CANNOT_PARSE_AS_TYPE,
+                                wrong, Integer.valueOf(position), type.getName());
     }
 
     /**
@@ -49,7 +52,7 @@ public class MathParseException extends 
      */
     public MathParseException(String wrong,
                               int position) {
-        addMessage(LocalizedFormats.CANNOT_PARSE,
-                   wrong, Integer.valueOf(position));
+        getContext().addMessage(LocalizedFormats.CANNOT_PARSE,
+                                wrong, Integer.valueOf(position));
     }
 }

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -18,19 +18,24 @@ package org.apache.commons.math.exceptio
 
 import org.apache.commons.math.exception.util.Localizable;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.util.ExceptionContext;
+import org.apache.commons.math.exception.util.ExceptionContextProvider;
 
 /**
  * Base class for all unsupported features.
- * It is used for all the exceptions that share the semantics of the standard
+ * It is used for all the exceptions that have the semantics of the standard
  * {@link UnsupportedOperationException}, but must also provide a localized
  * message.
  *
  * @since 2.2
  * @version $Revision$ $Date$
  */
-public class MathUnsupportedOperationException extends MathRuntimeException {
+public class MathUnsupportedOperationException extends UnsupportedOperationException
+    implements ExceptionContextProvider {
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
+    /** Context. */
+    private final ExceptionContext context = new ExceptionContext();
 
     /**
      * Default constructor.
@@ -45,6 +50,23 @@ public class MathUnsupportedOperationExc
      */
     public MathUnsupportedOperationException(Localizable pattern,
                                              Object ... args) {
-        addMessage(pattern, args);
+        context.addMessage(pattern, args);
+    }
+
+    /** {@inheritDoc} */
+    public ExceptionContext getContext() {
+        return context;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getMessage() {
+        return context.getMessage();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getLocalizedMessage() {
+        return context.getLocalizedMessage();
     }
 }

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -18,6 +18,8 @@ package org.apache.commons.math.exceptio
 
 import org.apache.commons.math.exception.util.Localizable;
 import org.apache.commons.math.exception.util.LocalizedFormats;
+import org.apache.commons.math.exception.util.ExceptionContext;
+import org.apache.commons.math.exception.util.ExceptionContextProvider;
 
 /**
  * This class is intended as a sort of communication channel between
@@ -28,15 +30,18 @@ import org.apache.commons.math.exception
  * @since 2.2
  * @version $Revision$ $Date$
  */
-public class MathUserException extends MathRuntimeException {
+public class MathUserException extends RuntimeException
+    implements ExceptionContextProvider {
     /** Serializable version Id. */
     private static final long serialVersionUID = -6024911025449780478L;
+    /** Context. */
+    private final ExceptionContext context = new ExceptionContext();
 
     /**
      * Build an exception with a default message.
      */
     public MathUserException() {
-        addMessage(LocalizedFormats.USER_EXCEPTION);
+        context.addMessage(LocalizedFormats.USER_EXCEPTION);
     }
 
     /**
@@ -45,7 +50,7 @@ public class MathUserException extends M
      */
     public MathUserException(final Throwable cause) {
         super(cause);
-        addMessage(LocalizedFormats.USER_EXCEPTION);
+        context.addMessage(LocalizedFormats.USER_EXCEPTION);
     }
 
     /**
@@ -56,7 +61,7 @@ public class MathUserException extends M
      */
     public MathUserException(final Localizable pattern,
                              final Object ... arguments) {
-        addMessage(pattern, arguments);
+        context.addMessage(pattern, arguments);
     }
 
     /**
@@ -70,6 +75,23 @@ public class MathUserException extends M
                              final Localizable pattern,
                              final Object ... arguments) {
         super(cause);
-        addMessage(pattern, arguments);
+        context.addMessage(pattern, arguments);
+    }
+
+    /** {@inheritDoc} */
+    public ExceptionContext getContext() {
+        return context;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getMessage() {
+        return context.getMessage();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getLocalizedMessage() {
+        return context.getLocalizedMessage();
     }
 }

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=1101029&r1=1101028&r2=1101029&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 May  9 13:54:34 2011
@@ -39,8 +39,7 @@ public class MaxCountExceededException e
      * @param max Maximum.
      */
     public MaxCountExceededException(Number max) {
-        super(LocalizedFormats.MAX_COUNT_EXCEEDED, max);
-        this.max = max;
+        this(LocalizedFormats.MAX_COUNT_EXCEEDED, max);
     }
     /**
      * Construct the exception with a specific context.
@@ -52,8 +51,8 @@ public class MaxCountExceededException e
     public MaxCountExceededException(Localizable specific,
                                      Number max,
                                      Object ... args) {
-        this(max);
-        addMessage(specific, max, args);
+        getContext().addMessage(specific, max, args);
+        this.max = max;
     }
 
     /**

Modified: commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/TooManyEvaluationsException.java
URL: http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/TooManyEvaluationsException.java?rev=1101029&r1=1101028&r2=1101029&view=diff
==============================================================================
--- commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/TooManyEvaluationsException.java (original)
+++ commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/TooManyEvaluationsException.java Mon May  9 13:54:34 2011
@@ -34,6 +34,7 @@ public class TooManyEvaluationsException
      * @param max Maximum number of evaluations.
      */
     public TooManyEvaluationsException(Number max) {
-        super(LocalizedFormats.EVALUATIONS, max);
+        super(max);
+        getContext().addMessage(LocalizedFormats.EVALUATIONS);
     }
 }

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=1101029&r1=1101028&r2=1101029&view=diff
==============================================================================
--- commons/proper/math/trunk/src/site/xdoc/changes.xml (original)
+++ commons/proper/math/trunk/src/site/xdoc/changes.xml Mon May  9 13:54:34 2011
@@ -52,6 +52,13 @@ 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="add" issue="MATH-566">
+        Created an "ExceptionContext" class: It provides the customization feature of
+        "MathRuntimeException" without imposing a singly rooted hierarchy of the Comons
+        Math exceptions.
+        Thus, those exceptions now inherit from their Java standard counterparts (e.g.
+        "MathIllegalArgumentException" inherits from "IllegalArgumentException").
+      </action>
       <action dev="luc" type="add" issue="MATH-567" due-to="Michel">
         Fixed conversion problems to/from 0 in Decimal Floating Point (Dfp) class.
       </action>