CompositeFormat

@Deprecated public class org.apache.commons.lang3.text.CompositeFormat extends Format[source]

Deprecated: As of 3.6, use Apache Commons Text CompositeFormat.

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.

Constructors

CompositeFormat(Format parser, Format formatter)

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

public CompositeFormat(Format parser, Format formatter)[source]

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

Parameters:
  • parser – implementation

  • formatter – implementation

Methods

StringBuffer

format(Object obj, StringBuffer toAppendTo, FieldPosition pos)

Uses the formatter Format instance.

Format

getFormatter()

Gets the formatter Format implementation.

Format

getParser()

Gets the parser Format implementation.

Object

parseObject(String source, ParsePosition pos)

Uses the parser Format instance.

String

reformat(String input)

Utility method to parse and then reformat a String.

public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)[source]

Uses the formatter Format instance.

Specified by:

format in class Format

Parameters:
  • obj – The object to format

  • toAppendTo – The StringBuffer to append to

  • pos – The FieldPosition to use (or ignore).

Returns:

toAppendTo

See also:

Format.format(Object, StringBuffer, FieldPosition)

public Format getFormatter()[source]

Gets the formatter Format implementation.

Returns:

The formatter Format implementation.

public Format getParser()[source]

Gets the parser Format implementation.

Returns:

parser Format implementation

public Object parseObject(String source, ParsePosition pos)[source]

Uses the parser Format instance.

Specified by:

parseObject in class Format

Parameters:
  • source – The String source

  • pos – 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)

public String reformat(String input) throws ParseException[source]

Utility method to parse and then reformat a String.

Parameters:

input – String to reformat

Returns:

A reformatted String

Throws:

ParseException – Thrown by parseObject(String) call.