Package org.apache.commons.text
Class CompositeFormat
- java.lang.Object
-
- java.text.Format
-
- org.apache.commons.text.CompositeFormat
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class CompositeFormat extends java.text.FormatFormats using one formatter and parses using a different formatter. An example of use for this would be a webapp where data is taken in one way and stored in a database another way.- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description CompositeFormat(java.text.Format parser, java.text.Format formatter)Constructs a format that points its parseObject method to one implementation and its format method to another.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringBufferformat(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)Formats the input.java.text.FormatgetFormatter()Gets the parser Format implementation.java.text.FormatgetParser()Gets the parser Format implementation.java.lang.ObjectparseObject(java.lang.String source, java.text.ParsePosition pos)Parses the input.java.lang.Stringreformat(java.lang.String input)Parses and then reformats a String.
-
-
-
Method Detail
-
format
public java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)Formats the input.- Specified by:
formatin classjava.text.Format- Parameters:
obj- the object to formattoAppendTo- theStringBufferto append topos- the FieldPosition to use (or ignore).- Returns:
toAppendTo- See Also:
Format.format(Object, StringBuffer, FieldPosition)
-
getFormatter
public java.text.Format getFormatter()
Gets the parser Format implementation.- Returns:
- formatter Format implementation
-
getParser
public java.text.Format getParser()
Gets the parser Format implementation.- Returns:
- parser Format implementation
-
parseObject
public java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)Parses the input.- Specified by:
parseObjectin classjava.text.Format- Parameters:
source- the String sourcepos- the ParsePosition containing the position to parse from, will be updated according to parsing success (index) or failure (error index)- Returns:
- The parsed Object
- See Also:
Format.parseObject(String, ParsePosition)
-
reformat
public java.lang.String reformat(java.lang.String input) throws java.text.ParseExceptionParses and then reformats a String.- Parameters:
input- String to reformat- Returns:
- A reformatted String
- Throws:
java.text.ParseException- thrown by parseObject(String) call
-
-