com.gridsystems.utils.text
Class ComposedFormat

java.lang.Object
  extended by java.text.Format
      extended by com.gridsystems.utils.text.ComposedFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class ComposedFormat
extends java.text.Format

Format implementation that performs a "chained" format over the passed object.

The internal formatters specified at construction time are sequentially invoked to perform the formatting in the same order they are in the array.

For example, an following code:

Format f = new ComposedFormat(
  new DecimalFormat("#,##0.00"),
  new MessageFormat("<span style='color:red'>{0}</span>"); );

System.out.println(f.format(new Integer(3500)));

will produce the next output:

<span style='color:red'>3.500,00</span>

Version:
1.0
Author:
Rodrigo Ruiz
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
ComposedFormat(java.text.Format... ff)
          Creates an instance with the specified array of internal formatters.
 
Method Summary
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          Formats an object and appends the resulting text to a given string buffer.
 java.lang.Object parseObject(java.lang.String s, java.text.ParsePosition pos)
          Not implemented.
 
Methods inherited from class java.text.Format
clone, format, formatToCharacterIterator, parseObject
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComposedFormat

public ComposedFormat(java.text.Format... ff)
Creates an instance with the specified array of internal formatters.

Parameters:
ff - The array of internal formatters
Method Detail

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)
Formats an object and appends the resulting text to a given string buffer. The pos argument is ignored in this implementation.

Specified by:
format in class java.text.Format
Parameters:
obj - The object to format
toAppendTo - Where the text is to be appended
pos - A FieldPosition identifying a field in the formatted text
Returns:
the string buffer passed in as toAppendTo, with formatted text appended
Throws:
java.lang.NullPointerException - if toAppendTo is null
java.lang.IllegalArgumentException - if any of the internal Formats cannot format the given object

parseObject

public java.lang.Object parseObject(java.lang.String s,
                                    java.text.ParsePosition pos)
Not implemented.

Specified by:
parseObject in class java.text.Format
Parameters:
s - the string
pos - the parse position
Returns:
an object (never)
Throws:
java.lang.UnsupportedOperationException - always


Copyright © 2007-2008 Grid Systems, S.A.. All Rights Reserved.