Class EmptyFormat

java.lang.Object
java.text.Format
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/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());
 
See Also:
  • Field Details

    • delegate

      private final Format delegate
      Refers to the wrapped Format that is used to forward #format and #parseObject.
    • emptyValue

      private final Object emptyValue
      Holds the object that represents the empty value. The result of formatting this value is the empty string; the result of parsing an empty string is this object.
  • Constructor Details

    • EmptyFormat

      public EmptyFormat(Format delegate)
      Constructs an EmptyFormat 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
    • EmptyFormat

      public EmptyFormat(Format delegate, Object emptyValue)
      Constructs an EmptyFormat 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 Details