EmptyNumberFormat (JGoodies Common 1.4 API)
Date: 2012-07-24

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.jgoodies.common.format
Class EmptyNumberFormat

    java.lang.Object
      java.text.Format
          java.text.NumberFormat
              com.jgoodies.common.format.EmptyNumberFormat

All Implemented Interfaces:
  Serializable, Cloneable

    public final class EmptyNumberFormat

extends NumberFormat

Wraps a given `NumberFormat` and adds behavior to convert to/from the empty string. Therefore it holds an empty value 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 NumberFormat.

Examples:

     new EmptyNumberFormat(NumberFormat().getInstance());
     new EmptyNumberFormat(NumberFormat().getIntegerInstance(), -1);

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

Nested Class Summary

Nested classes/interfaces inherited from class java.text.NumberFormat
`NumberFormat.Field`

Field Summary

Fields inherited from class java.text.NumberFormat
`FRACTION_FIELD, INTEGER_FIELD`

Constructor Summary
`EmptyNumberFormat(NumberFormat delegate)` Constructs an EmptyNumberFormat that wraps the given mandatory format to convert `null` to the empty string and vice versa.
`EmptyNumberFormat(NumberFormat delegate, int emptyValue)` Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the given `emptyValue` to the empty string and vice versa.
`EmptyNumberFormat(NumberFormat delegate, Number emptyValue)` Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the given `emptyValue` to the empty string and vice versa.

Method Summary
`StringBuffer` | `format(double number, StringBuffer toAppendTo, FieldPosition pos)`
`StringBuffer` | `format(long number, StringBuffer toAppendTo, FieldPosition pos)`
`StringBuffer` | `format(Object obj, StringBuffer toAppendTo, FieldPosition pos)` If `obj` is equal to the emptyValue, `toAppendTo` is returned.
`Number` | `parse(String source)` If `source` is empty or whitespace, the emptyValue is returned.
`Number` | `parse(String source, ParsePosition pos)`
`Object` | `parseObject(String source)` If `source` is empty or whitespace, the emptyValue is returned.

Methods inherited from class java.text.NumberFormat
`clone, equals, format, format, getAvailableLocales, getCurrency, getCurrencyInstance, getCurrencyInstance, getInstance, getInstance, getIntegerInstance, getIntegerInstance, getMaximumFractionDigits, getMaximumIntegerDigits, getMinimumFractionDigits, getMinimumIntegerDigits, getNumberInstance, getNumberInstance, getPercentInstance, getPercentInstance, getRoundingMode, hashCode, isGroupingUsed, isParseIntegerOnly, parseObject, setCurrency, setGroupingUsed, setMaximumFractionDigits, setMaximumIntegerDigits, setMinimumFractionDigits, setMinimumIntegerDigits, setParseIntegerOnly, setRoundingMode`

Methods inherited from class java.text.Format
`format, formatToCharacterIterator`

Methods inherited from class java.lang.Object
`finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### EmptyNumberFormat

    public EmptyNumberFormat(NumberFormat delegate)

  Constructs an EmptyNumberFormat that wraps the given mandatory format 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`

### EmptyNumberFormat

    public EmptyNumberFormat(NumberFormat delegate,
                             int emptyValue)

  Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the given `emptyValue` to the empty string 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`

### EmptyNumberFormat

    public EmptyNumberFormat(NumberFormat delegate,
                             Number emptyValue)

  Constructs an EmptyNumberFormat that wraps the given mandatory format to convert the given `emptyValue` to the empty string 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)

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

  Overrides:
    `format` in class `NumberFormat`

### format

    public StringBuffer format(double number,
                               StringBuffer toAppendTo,
                               FieldPosition pos)

  Specified by:
    `format` in class `NumberFormat`

### format

    public StringBuffer format(long number,
                               StringBuffer toAppendTo,
                               FieldPosition pos)

  Specified by:
    `format` in class `NumberFormat`

### parseObject

    public Object parseObject(String source)
                       throws ParseException

  If `source` is empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly via `parse(String, ParsePosition)`.

  Overrides:
    `parseObject` in class `Format`
  Throws:
    `ParseException`

### parse

    public Number parse(String source)
                 throws ParseException

  If `source` is empty or whitespace, the emptyValue is returned. Otherwise parsing is forwarded to the delegate - indirectly via `parse(String, ParsePosition)`.

  Overrides:
    `parse` in class `NumberFormat`
  Throws:
    `ParseException`

### parse

    public Number parse(String source,
                        ParsePosition pos)

  Specified by:
    `parse` in class `NumberFormat`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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