com.jgoodies.validation.tutorial.formatted.format
Class DisplayFormat

java.lang.Object
  extended by java.text.Format
      extended by com.jgoodies.validation.tutorial.formatted.format.DisplayFormat
All Implemented Interfaces:
Serializable, Cloneable

public final class DisplayFormat
extends Format

Wraps a given Format and overrides that null values are formatted to the empty string.

Examples:

 new DisplayFormat(DateFormat.getDateInstance());
 new DisplayFormat(new NumberFormat());
 new DisplayFormat(new NumberFormat(), true);
 

Version:
$Revision: 1.12 $
Author:
Karsten Lentzsch
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
Format.Field
 
Constructor Summary
DisplayFormat(Format format)
          Constructs an EmptyFormat that wraps the given format to convert null to the empty string and vice versa.
DisplayFormat(Format format, boolean showClass)
          Constructs an EmptyFormat that wraps the given format to convert null to the empty string and vice versa.
 
Method Summary
 StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
          Formats an object and appends the resulting text to a given string buffer.
 Object parseObject(String source, ParsePosition pos)
          Parses text from a string to produce an object.
 
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

DisplayFormat

public DisplayFormat(Format format)
Constructs an EmptyFormat that wraps the given format to convert null to the empty string and vice versa.

Parameters:
format - the format that handles the standard cases

DisplayFormat

public DisplayFormat(Format format,
                     boolean showClass)
Constructs an EmptyFormat that wraps the given format to convert null to the empty string and vice versa.

Parameters:
format - the format that handles the standard cases
showClass - true to format the value's class
Method Detail

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)
Formats an object and appends the resulting text to a given string buffer. If the pos argument identifies a field used by the format, then its indices are set to the beginning and end of the first such field encountered.

Specified by:
format in class 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:
NullPointerException - if toAppendTo or pos is null
IllegalArgumentException - if the Format cannot format the given object

parseObject

public Object parseObject(String source,
                          ParsePosition pos)
Parses text from a string to produce an object.

Specified by:
parseObject in class Format
Parameters:
source - A String, part of which should be parsed.
pos - A ParsePosition object with index and error index information as described above.
Returns:
An Object parsed from the string. In case of error, returns null.
Throws:
NullPointerException - if pos is null.


Copyright © 2003-2008 JGoodies Karsten Lentzsch. All Rights Reserved.