You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by ba...@apache.org on 2006/05/01 08:37:16 UTC

svn commit: r398536 - in /jakarta/commons/proper/lang/trunk/src: java/org/apache/commons/lang/text/CompositeFormat.java test/org/apache/commons/lang/text/CompositeFormatTest.java

Author: bayard
Date: Sun Apr 30 23:37:14 2006
New Revision: 398536

URL: http://svn.apache.org/viewcvs?rev=398536&view=rev
Log:
Archimedes Trajano offered another method for the class

Modified:
    jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/CompositeFormat.java
    jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/CompositeFormatTest.java

Modified: jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/CompositeFormat.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/CompositeFormat.java?rev=398536&r1=398535&r2=398536&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/CompositeFormat.java (original)
+++ jakarta/commons/proper/lang/trunk/src/java/org/apache/commons/lang/text/CompositeFormat.java Sun Apr 30 23:37:14 2006
@@ -18,6 +18,7 @@
 import java.text.Format;
 import java.text.FieldPosition;
 import java.text.ParsePosition;
+import java.text.ParseException;
 
 /**
  * Formats using one formatter and parses using a different formatter.
@@ -77,6 +78,17 @@
      */
     public Format getFormatter() {
         return this.formatter;
+    }
+
+    /**
+     * Utility method to parse and then reformat a String. 
+     * 
+     * @param source String to reformat
+     * @return A reformatted String
+     * @throws ParseException thrown by parseObject(String) call
+     */
+    public String reformat(String input) throws ParseException {
+        return format(parseObject(input));
     }
 
 }

Modified: jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/CompositeFormatTest.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/CompositeFormatTest.java?rev=398536&r1=398535&r2=398536&view=diff
==============================================================================
--- jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/CompositeFormatTest.java (original)
+++ jakarta/commons/proper/lang/trunk/src/test/org/apache/commons/lang/text/CompositeFormatTest.java Sun Apr 30 23:37:14 2006
@@ -25,6 +25,9 @@
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
 /**
  * Unit tests for {@link org.apache.commons.lang.text.CompositeFormat}.
  */
@@ -92,6 +95,15 @@
         composite.format(new Object(), new StringBuffer(), null);
         assertEquals( "Parser get method incorrectly implemented", parser, composite.getParser() );
         assertEquals( "Formatter get method incorrectly implemented", formatter, composite.getFormatter() );
+    }
+
+    public void testUsage() throws Exception {
+        Format f1 = new SimpleDateFormat("MMddyyyy", Locale.ENGLISH);
+        Format f2 = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
+        CompositeFormat c = new CompositeFormat(f1, f2);
+        String testString = "January 3, 2005";
+        assertEquals(testString, c.format(c.parseObject("01032005")));
+        assertEquals(testString, c.reformat("01032005"));
     }
 
 }



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