commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject svn commit: r511531 - /jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
Date Sun, 25 Feb 2007 15:48:08 GMT
Author: luc
Date: Sun Feb 25 07:48:07 2007
New Revision: 511531

URL: http://svn.apache.org/viewvc?view=rev&rev=511531
Log:
make the code java 1.3 compatible

Modified:
    jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java

Modified: jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java?view=diff&rev=511531&r1=511530&r2=511531
==============================================================================
--- jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
(original)
+++ jakarta/commons/proper/math/trunk/src/java/org/apache/commons/math/MathException.java
Sun Feb 25 07:48:07 2007
@@ -102,6 +102,20 @@
     }
 
     /**
+     * Builds a message string by from a pattern and its arguments.
+     * @param pattern format specifier
+     * @param arguments format arguments
+     * @param locale Locale in which the message should be translated
+     * @return a message string
+     */
+    private static String buildMessage(String pattern, Object[] arguments, Locale locale)
{
+        // do it the hard way, for Java 1.3. compatibility
+        MessageFormat mf = new MessageFormat(translate(pattern, locale));
+        mf.setLocale(locale);
+        return mf.format(arguments);        
+    }
+
+    /**
      * Constructs a new <code>MathException</code> with no
      * detail message.
      */
@@ -134,7 +148,7 @@
      * @param arguments format arguments
      */
     public MathException(String pattern, Object[] arguments) {
-      super(new MessageFormat(pattern, Locale.US).format(arguments));
+      super(buildMessage(pattern, arguments, Locale.US));
       this.pattern   = pattern;
       this.arguments = arguments;
       this.rootCause = null;
@@ -180,7 +194,7 @@
      *                   to be thrown.
      */
     public MathException(String pattern, Object[] arguments, Throwable rootCause) {
-      super(new MessageFormat(pattern, Locale.US).format(arguments));
+      super(buildMessage(pattern, arguments, Locale.US));
       this.pattern   = pattern;
       this.arguments = arguments;
       this.rootCause = rootCause;
@@ -209,10 +223,7 @@
      * @return localized message
      */
     public String getMessage(Locale locale) {
-        if (pattern == null) {
-            return null;
-        }
-        return new MessageFormat(translate(pattern, locale), locale).format(arguments);
+        return (pattern == null) ? null : buildMessage(pattern, arguments, locale);
     }
 
     /**



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


Mime
View raw message