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 [EMAIL PROTECTED] 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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]