com.jgoodies.common.format
Class EmptyFormat

java.lang.Object
  extended by java.text.Format
      extended by com.jgoodies.common.format.EmptyFormat
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class EmptyFormat
extends java.text.Format

Wraps a given Format and adds behavior to convert to/from the empty string. Therefore it holds an empty value (often null) that is mapped to/from the empty string. The #format result of the empty value is the empty string, and the #parse result of the empty string is the empty value. In all other cases the formatting and parsing is forwarded to the wrapped Format.

If you want to wrap a DateFormat or NumberFormat, you may use EmptyDateFormat or EmptyNumberFormat resp. Examples:

 new EmptyFormat(new WeightFormat());
 

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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
java.text.Format.Field
 
Constructor Summary
EmptyFormat(java.text.Format format)
          Constructs an EmptyFormat that wraps the given format to convert null to the empty string and vice versa.
EmptyFormat(java.text.Format format, java.lang.Object emptyValue)
          Constructs an EmptyFormat that wraps the given format to convert the given emptyValue to the empty string and vice versa.
 
Method Summary
 java.lang.StringBuffer format(java.lang.Object obj, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)
          
 java.text.AttributedCharacterIterator formatToCharacterIterator(java.lang.Object obj)
           
 java.lang.Object parseObject(java.lang.String source)
          
 java.lang.Object parseObject(java.lang.String source, java.text.ParsePosition pos)
           
 
Methods inherited from class java.text.Format
clone, format
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmptyFormat

public EmptyFormat(java.text.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

EmptyFormat

public EmptyFormat(java.text.Format format,
                   java.lang.Object emptyValue)
Constructs an EmptyFormat that wraps the given format to convert the given emptyValue to the empty string and vice versa.

Parameters:
format - the format that handles non-null values
emptyValue - the representation of the empty string
Method Detail

format

public java.lang.StringBuffer format(java.lang.Object obj,
                                     java.lang.StringBuffer toAppendTo,
                                     java.text.FieldPosition pos)

If obj is equal to the emptyValue, toAppendTo is returned. Otherwise the format is forwarded to the delegate.

Specified by:
format in class java.text.Format

parseObject

public java.lang.Object parseObject(java.lang.String source)
                             throws java.text.ParseException

If source is empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate.

Overrides:
parseObject in class java.text.Format
Throws:
java.text.ParseException

parseObject

public final java.lang.Object parseObject(java.lang.String source,
                                          java.text.ParsePosition pos)
Specified by:
parseObject in class java.text.Format

formatToCharacterIterator

public final java.text.AttributedCharacterIterator formatToCharacterIterator(java.lang.Object obj)
Overrides:
formatToCharacterIterator in class java.text.Format


Copyright © 2009-2011 JGoodies Karsten Lentzsch. All Rights Reserved.