Class EmptyDateFormat

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.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:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class java.text.DateFormat

        java.text.DateFormat.Field
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Date emptyValue
      Holds the object that represents the empty value.
      • Fields inherited from class java.text.DateFormat

        AM_PM_FIELD, calendar, DATE_FIELD, DAY_OF_WEEK_FIELD, DAY_OF_WEEK_IN_MONTH_FIELD, DAY_OF_YEAR_FIELD, DEFAULT, ERA_FIELD, FULL, HOUR_OF_DAY0_FIELD, HOUR_OF_DAY1_FIELD, HOUR0_FIELD, HOUR1_FIELD, LONG, MEDIUM, MILLISECOND_FIELD, MINUTE_FIELD, MONTH_FIELD, numberFormat, SECOND_FIELD, SHORT, TIMEZONE_FIELD, WEEK_OF_MONTH_FIELD, WEEK_OF_YEAR_FIELD, YEAR_FIELD
    • Constructor Summary

      Constructors 
      Constructor Description
      EmptyDateFormat​(java.text.DateFormat delegate)
      Constructs an EmptyFormat that wraps the given mandatory format to convert null to the empty string and vice versa.
      EmptyDateFormat​(java.text.DateFormat delegate, java.util.Date emptyValue)
      Constructs an EmptyFormat that wraps the given mandatory format to convert the given emptyValue to the empty string and vice versa.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.StringBuffer format​(java.util.Date date, java.lang.StringBuffer toAppendTo, java.text.FieldPosition pos)  
      java.util.Date parse​(java.lang.String source, java.text.ParsePosition pos)  
      • Methods inherited from class java.text.DateFormat

        clone, equals, format, format, getAvailableLocales, getDateInstance, getDateInstance, getDateInstance, getDateTimeInstance, getDateTimeInstance, getDateTimeInstance, getInstance, getTimeInstance, getTimeInstance, getTimeInstance, hashCode, parse, parseObject
      • Methods inherited from class java.text.Format

        format, parseObject
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • emptyValue

        private final java.util.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 Detail

      • EmptyDateFormat

        public EmptyDateFormat​(java.text.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:
        java.lang.NullPointerException - if delegate is null
      • EmptyDateFormat

        public EmptyDateFormat​(java.text.DateFormat delegate,
                               java.util.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:
        java.lang.NullPointerException - if delegate is null
    • Method Detail

      • format

        public java.lang.StringBuffer format​(java.util.Date date,
                                             java.lang.StringBuffer toAppendTo,
                                             java.text.FieldPosition pos)
        Specified by:
        format in class AbstractWrappedDateFormat
      • parse

        public java.util.Date parse​(java.lang.String source,
                                    java.text.ParsePosition pos)
        Specified by:
        parse in class AbstractWrappedDateFormat