You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DateToLongConverter.java 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.converter;
  5. import java.util.Date;
  6. import java.util.Locale;
  7. /**
  8. * A converter that converts from {@link Long} to {@link Date} and back.
  9. *
  10. * @author Vaadin Ltd
  11. * @version
  12. * @VERSION@
  13. * @since 7.0
  14. */
  15. public class DateToLongConverter implements Converter<Date, Long> {
  16. /*
  17. * (non-Javadoc)
  18. *
  19. * @see
  20. * com.vaadin.data.util.converter.Converter#convertToModel(java.lang.Object,
  21. * java.util.Locale)
  22. */
  23. @Override
  24. public Long convertToModel(Date value, Locale locale) {
  25. if (value == null) {
  26. return null;
  27. }
  28. return value.getTime();
  29. }
  30. /*
  31. * (non-Javadoc)
  32. *
  33. * @see
  34. * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang
  35. * .Object, java.util.Locale)
  36. */
  37. @Override
  38. public Date convertToPresentation(Long value, Locale locale) {
  39. if (value == null) {
  40. return null;
  41. }
  42. return new Date(value);
  43. }
  44. /*
  45. * (non-Javadoc)
  46. *
  47. * @see com.vaadin.data.util.converter.Converter#getModelType()
  48. */
  49. @Override
  50. public Class<Long> getModelType() {
  51. return Long.class;
  52. }
  53. /*
  54. * (non-Javadoc)
  55. *
  56. * @see com.vaadin.data.util.converter.Converter#getPresentationType()
  57. */
  58. @Override
  59. public Class<Date> getPresentationType() {
  60. return Date.class;
  61. }
  62. }