Package org.apache.commons.text
Class CompositeFormat
- java.lang.Object
-
- java.text.Format
-
- org.apache.commons.text.CompositeFormat
-
- All Implemented Interfaces:
Serializable,Cloneable
public class CompositeFormat extends Format
Formats 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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.text.Format
Format.Field
-
-
Constructor Summary
Constructors Constructor Description CompositeFormat(Format parser, 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 StringBufferformat(Object obj, StringBuffer toAppendTo, FieldPosition pos)Formats the input.FormatgetFormatter()Gets the parser Format implementation.FormatgetParser()Gets the parser Format implementation.ObjectparseObject(String source, ParsePosition pos)Parses the input.Stringreformat(String input)Parses and then reformats a String.-
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
-
-
-
-
Constructor Detail
-
CompositeFormat
public CompositeFormat(Format parser, Format formatter)
Constructs a format that points its parseObject method to one implementation and its format method to another.- Parameters:
parser- implementationformatter- implementation
-
-
Method Detail
-
format
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
Formats the input.- Specified by:
formatin classFormat- 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 Format getFormatter()
Gets the parser Format implementation.- Returns:
- formatter Format implementation
-
getParser
public Format getParser()
Gets the parser Format implementation.- Returns:
- parser Format implementation
-
parseObject
public Object parseObject(String source, ParsePosition pos)
Parses the input.- Specified by:
parseObjectin classFormat- 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 String reformat(String input) throws ParseException
Parses and then reformats a String.- Parameters:
input- String to reformat- Returns:
- A reformatted String
- Throws:
ParseException- thrown by parseObject(String) call
-
-