Author: luc
Date: Sun Nov 14 21:32:08 2010
New Revision: 1035072

URL: http://svn.apache.org/viewvc?rev=1035072&view=rev
Log:
reverting change introduced in 1035003:
it was the javadoc that did not correspond to the intended behavior, not the 
code

Modified:
    
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java
    
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/MessageFactoryTest.java

Modified: 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java?rev=1035072&r1=1035071&r2=1035072&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java
 (original)
+++ 
commons/proper/math/trunk/src/main/java/org/apache/commons/math/exception/util/MessageFactory.java
 Sun Nov 14 21:32:08 2010
@@ -52,42 +52,25 @@ public class MessageFactory {
      * @param locale Locale in which the message should be translated.
      * @param specific Format specifier (may be null).
      * @param general Format specifier (may be null).
-     * @param arguments Format arguments. They will be substituted first in
-     * the {...@code specific} format specifier, then the remaining arguments
-     * will be substituted in the {...@code general} format specifier.
+     * @param arguments Format arguments. They will be substituted in
+     * <em>both</em> the {...@code general} and {...@code specific} format 
specifiers.
      * @return a localized message string.
      */
     public static String buildMessage(Locale locale,
                                       Localizable specific,
                                       Localizable general,
                                       Object ... arguments) {
-
         final StringBuilder sb = new StringBuilder();
-        Object[] generalArgs = arguments;
-
-        if (specific != null) {
-
-            final MessageFormat specificFmt = new 
MessageFormat(specific.getLocalizedString(locale), locale);
-
-            // split the arguments: first specific ones then general ones
-            final int nbSpecific = Math.min(arguments.length, 
specificFmt.getFormatsByArgumentIndex().length);
-            final int nbGeneral  = arguments.length - nbSpecific;
-            Object[] specificArgs = new Object[nbSpecific];
-            System.arraycopy(arguments, 0, specificArgs, 0, nbSpecific);
-            generalArgs = new Object[nbGeneral];
-            System.arraycopy(arguments, nbSpecific, generalArgs, 0, nbGeneral);
-
-            // build the message
-            sb.append(specificFmt.format(specificArgs));
-
-        }
-
         if (general != null) {
-            if (specific != null) {
+            final MessageFormat fmt = new 
MessageFormat(general.getLocalizedString(locale), locale);
+            sb.append(fmt.format(arguments));
+        }
+        if (specific != null) {
+            if (general != null) {
                 sb.append(": ");
             }
-            final MessageFormat generalFmt  = new 
MessageFormat(general.getLocalizedString(locale), locale);
-            sb.append(generalFmt.format(generalArgs));
+            final MessageFormat fmt = new 
MessageFormat(specific.getLocalizedString(locale), locale);
+            sb.append(fmt.format(arguments));
         }
 
         return sb.toString();

Modified: 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/MessageFactoryTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/MessageFactoryTest.java?rev=1035072&r1=1035071&r2=1035072&view=diff
==============================================================================
--- 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/MessageFactoryTest.java
 (original)
+++ 
commons/proper/math/trunk/src/test/java/org/apache/commons/math/exception/util/MessageFactoryTest.java
 Sun Nov 14 21:32:08 2010
@@ -29,26 +29,25 @@ public class MessageFactoryTest {
         Localizable general  = new DummyLocalizable("general  {0} / {1}");
         String message = MessageFactory.buildMessage(Locale.FRENCH, specific, 
general,
                                                      0, 1, 2, 'a', 'b');
-        Assert.assertEquals("specific 0 - 1 - 2: general  a / b", message);
+        Assert.assertEquals("general  0 / 1: specific 0 - 1 - 2", message);
     }
 
     @Test
     public void testNullSpecific() {
         Localizable general  = new DummyLocalizable("general  {0} / {1}");
         String message = MessageFactory.buildMessage(Locale.FRENCH, null, 
general,
-                                                     'a', 'b');
-        Assert.assertEquals("general  a / b", message);
+                                                     0, 1, 2, 'a', 'b');
+        Assert.assertEquals("general  0 / 1", message);
     }
 
     @Test
     public void testNullGeneral() {
         Localizable specific = new DummyLocalizable("specific {0} - {1} - 
{2}");
         String message = MessageFactory.buildMessage(Locale.FRENCH, specific, 
null,
-                                                     0, 1, 2);
+                                                     0, 1, 2, 'a', 'b');
         Assert.assertEquals("specific 0 - 1 - 2", message);
     }
 
-
     @Test
     public void testNull() {
         String message = MessageFactory.buildMessage(Locale.FRENCH, null, 
null, "nothing");


Reply via email to