Archimedes Trajano offered another method for the class
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@398536 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
79c3898c90
commit
da0e534f15
|
@ -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.
|
||||
|
@ -79,4 +80,15 @@ 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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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}.
|
||||
*/
|
||||
|
@ -94,4 +97,13 @@ public Object parseObject(String source, ParsePosition pos) {
|
|||
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"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue