com.jgoodies.common.format
Class EmptyFormat

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

public class EmptyFormat
extends Format

Wraps a given Format and adds behavior to convert to/fro the empty string. Therefore it holds an empty valuenull) that i mapped to/from the empty string. The #format resul of the empty value is the empty string, and the #parseEmptyDateFormat or EmptyNumberFormat resp Examples:

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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.text.Format
Format.Field
 
Constructor Summary
EmptyFormat(Format delegate)
          Constructs an EmptyFormat that wraps the given mandatory forma to convert null to the empty string and vice versa.
EmptyFormat(Format delegate, Object emptyValue)
          Constructs an EmptyFormat that wraps the given mandatory forma to convert the given emptyValue to the empty strin and vice versa.
 
Method Summary
 StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos)
           If obj is equal to the emptyValue toAppendTo is returned.
 AttributedCharacterIterator formatToCharacterIterator(Object obj)
           
 Object parseObject(String source)
           If source is empty or whitespace, the emptyValue
 Object parseObject(String source, 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(Format delegate)
Constructs an EmptyFormat that wraps the given mandatory forma to convert null to the empty string and vice versa.

Parameters:
delegate - the format that handles the standard cases
Throws:
NullPointerException - if delegate is null

EmptyFormat

public EmptyFormat(Format delegate,
                   Object emptyValue)
Constructs an EmptyFormat that wraps the given mandatory forma to convert the given emptyValue to the empty strin and vice versa.

Parameters:
delegate - the format that handles non-null values
emptyValue - the representation of the empty string
Throws:
NullPointerException - if delegate is null
Method Detail

format

public StringBuffer format(Object obj,
                           StringBuffer toAppendTo,
                           FieldPosition pos)

obj is equal to the emptyValue toAppendTo is returned. Otherwise the forma is forwarded to the delegate.

Specified by:
format in class Format

parseObject

public Object parseObject(String source)
                   throws ParseException

source is empty or whitespace, the emptyValue

Overrides:
parseObject in class Format
Throws:
ParseException

parseObject

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

formatToCharacterIterator

public final AttributedCharacterIterator formatToCharacterIterator(Object obj)
Overrides:
formatToCharacterIterator in class Format


Copyright © 2009-2013 JGoodies Software GmbH. All Rights Reserved.