Class DateConverter

  • All Implemented Interfaces:
    ValueConverter<java.util.Date>

    public class DateConverter
    extends java.lang.Object
    implements ValueConverter<java.util.Date>
    Converts values to Dates using a DateFormat object.
    Author:
    Paul Holser
    • Constructor Summary

      Constructors 
      Constructor Description
      DateConverter​(java.text.DateFormat formatter)
      Creates a converter that uses the given date formatter/parser.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.Date convert​(java.lang.String value)
      Converts the given string value into a Java type.
      static DateConverter datePattern​(java.lang.String pattern)
      Creates a converter that uses a SimpleDateFormat with the given date/time pattern.
      java.lang.String valuePattern()
      Gives a string that describes the pattern of the values this converter expects, if any.
      java.lang.Class<java.util.Date> valueType()
      Gives the class of the type of values this converter converts to.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DateConverter

        public DateConverter​(java.text.DateFormat formatter)
        Creates a converter that uses the given date formatter/parser.
        Parameters:
        formatter - the formatter/parser to use
        Throws:
        java.lang.NullPointerException - if formatter is null
    • Method Detail

      • datePattern

        public static DateConverter datePattern​(java.lang.String pattern)
        Creates a converter that uses a SimpleDateFormat with the given date/time pattern. The date formatter created is not lenient.
        Parameters:
        pattern - expected date/time pattern
        Returns:
        the new converter
        Throws:
        java.lang.NullPointerException - if pattern is null
        java.lang.IllegalArgumentException - if pattern is invalid
      • convert

        public java.util.Date convert​(java.lang.String value)
        Description copied from interface: ValueConverter
        Converts the given string value into a Java type.
        Specified by:
        convert in interface ValueConverter<java.util.Date>
        Parameters:
        value - the string to convert
        Returns:
        the converted value
      • valueType

        public java.lang.Class<java.util.Date> valueType()
        Description copied from interface: ValueConverter
        Gives the class of the type of values this converter converts to.
        Specified by:
        valueType in interface ValueConverter<java.util.Date>
        Returns:
        the target class for conversion
      • valuePattern

        public java.lang.String valuePattern()
        Description copied from interface: ValueConverter
        Gives a string that describes the pattern of the values this converter expects, if any. For example, a date converter can respond with a date format string.
        Specified by:
        valuePattern in interface ValueConverter<java.util.Date>
        Returns:
        a value pattern, or null if there's nothing interesting here