Class 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.
    Version:
    $Id: CompositeFormat.java 905636 2010-02-02 14:03:32Z niallp $
    See Also:
    Serialized Form
    • Constructor Detail

      • CompositeFormat

        public CompositeFormat​(Format parser,
                               Format formatter)
        Create a format that points its parseObject method to one implementation and its format method to another.
        Parameters:
        parser - implementation
        formatter - implementation
    • Method Detail

      • parseObject

        public Object parseObject​(String source,
                                  ParsePosition pos)
        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)
      • getParser

        public Format getParser()
        Provides access to the parser Format implementation.
        Returns:
        parser Format implementation
      • getFormatter

        public Format getFormatter()
        Provides access to the parser Format implementation.
        Returns:
        formatter Format implementation
      • reformat

        public String reformat​(String input)
                        throws ParseException
        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