Top Description Fields Constructors Methods
org.apache.commons.text

public Class CompositeFormat

extends Format
Class Inheritance
Imports
java.text.FieldPosition, .Format, .ParseException, .ParsePosition

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

Field Summary

Modifier and TypeField and Description
private final Format
formatter

The formatter to use.

private final Format
parser

The parser to use.

private static final long
serialVersionUID

Hides java.text.Format.serialVersionUID.

Required for serialization support.

Constructor Summary

AccessConstructor and Description
public
CompositeFormat(final Format
implementation.
parser
,
final Format
implementation.
formatter
)

Constructs a format that points its parseObject method to one implementation and its format method to another.

Method Summary

Modifier and TypeMethod and Description
public StringBuffer

Returns:

toAppendTo.
format
(final Object
the object to format.
obj
,
final StringBuffer
the StringBuffer to append to.
toAppendTo
,
final FieldPosition
the FieldPosition to use (or ignore).
pos
)

Implements abstract java.text.Format.format.

Formats the input.

public Format

Returns:

formatter Format implementation
getFormatter
()

Gets the parser Format implementation.

public Format

Returns:

parser Format implementation
getParser
()

Gets the parser Format implementation.

public Object

Returns:

The parsed Object.
parseObject
(final String
the String source.
source
,
final ParsePosition
the ParsePosition containing the position to parse from, will be updated according to parsing success (index) or failure (error index).
pos
)

Implements abstract java.text.Format.parseObject.

Parses the input.

public String

Returns:

A reformatted String.
reformat
(final String
String to reformat.
input
)

Parses and then reformats a String.

Inherited from java.text.Format:
cloneformatformatToCharacterIteratorparseObject

Field Detail

formatterback to summary
private final Format formatter

The formatter to use.

parserback to summary
private final Format parser

The parser to use.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.text.Format.serialVersionUID.

Required for serialization support.

See Also
java.io.Serializable

Constructor Detail

CompositeFormatback to summary
public CompositeFormat(final Format parser, final Format formatter)

Constructs a format that points its parseObject method to one implementation and its format method to another.

Parameters
parser:Format

implementation.

formatter:Format

implementation.

Method Detail

formatback to summary
public StringBuffer format(final Object obj, final StringBuffer toAppendTo, final FieldPosition pos)

Implements abstract java.text.Format.format.

Formats the input.

Parameters
obj:Object

the object to format.

toAppendTo:StringBuffer

the StringBuffer to append to.

pos:FieldPosition

the FieldPosition to use (or ignore).

Returns:StringBuffer

toAppendTo.

Annotations
@Override
See Also
Format#format(Object, StringBuffer, FieldPosition)
getFormatterback to summary
public Format getFormatter()

Gets the parser Format implementation.

Returns:Format

formatter Format implementation

getParserback to summary
public Format getParser()

Gets the parser Format implementation.

Returns:Format

parser Format implementation

parseObjectback to summary
public Object parseObject(final String source, final ParsePosition pos)

Implements abstract java.text.Format.parseObject.

Parses the input.

Parameters
source:String

the String source.

pos:ParsePosition

the ParsePosition containing the position to parse from, will be updated according to parsing success (index) or failure (error index).

Returns:Object

The parsed Object.

Annotations
@Override
See Also
Format#parseObject(String, ParsePosition)
reformatback to summary
public String reformat(final String input) throws ParseException

Parses and then reformats a String.

Parameters
input:String

String to reformat.

Returns:String

A reformatted String.

Exceptions
ParseException:
thrown by parseObject(String) call.