Class EmptyDateFormat

All Implemented Interfaces:
Serializable, Cloneable

public final class EmptyDateFormat extends AbstractWrappedDateFormat
Wraps a given DateFormat 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 DateFormat.

Often the empty value is null but you can construct an EmptyDateFormat with a given Date.

Examples:

 new EmptyDateFormat(DateFormat.getDateInstance());
 new EmptyDateFormat(DateFormat.getDateInstance(), new Date());

 new EmptyDateFormat(DateFormat.getDateInstance(DateFormat.SHORT));
 new EmptyDateFormat(DateFormat.getDateInstance(DateFormat.SHORT), new Date());
 
See Also:
  • Field Details

    • emptyValue

      private final Date 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

    • EmptyDateFormat

      public EmptyDateFormat(DateFormat 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
    • EmptyDateFormat

      public EmptyDateFormat(DateFormat delegate, Date 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