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.

ReverseConverter.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.data.util.converter;
  5. import java.util.Locale;
  6. /**
  7. * A converter that wraps another {@link Converter} and reverses source and
  8. * target types.
  9. *
  10. * @param <MODEL>
  11. * The source type
  12. * @param <PRESENTATION>
  13. * The target type
  14. *
  15. * @author Vaadin Ltd
  16. * @version
  17. * @VERSION@
  18. * @since 7.0
  19. */
  20. public class ReverseConverter<PRESENTATION, MODEL> implements
  21. Converter<PRESENTATION, MODEL> {
  22. private Converter<MODEL, PRESENTATION> realConverter;
  23. /**
  24. * Creates a converter from source to target based on a converter that
  25. * converts from target to source.
  26. *
  27. * @param converter
  28. * The converter to use in a reverse fashion
  29. */
  30. public ReverseConverter(Converter<MODEL, PRESENTATION> converter) {
  31. this.realConverter = converter;
  32. }
  33. /*
  34. * (non-Javadoc)
  35. *
  36. * @see com.vaadin.data.util.converter.Converter#convertToModel(java
  37. * .lang.Object, java.util.Locale)
  38. */
  39. @Override
  40. public MODEL convertToModel(PRESENTATION value, Locale locale)
  41. throws com.vaadin.data.util.converter.Converter.ConversionException {
  42. return realConverter.convertToPresentation(value, locale);
  43. }
  44. /*
  45. * (non-Javadoc)
  46. *
  47. * @see
  48. * com.vaadin.data.util.converter.Converter#convertToPresentation(java.lang
  49. * .Object, java.util.Locale)
  50. */
  51. @Override
  52. public PRESENTATION convertToPresentation(MODEL value, Locale locale)
  53. throws com.vaadin.data.util.converter.Converter.ConversionException {
  54. return realConverter.convertToModel(value, locale);
  55. }
  56. /*
  57. * (non-Javadoc)
  58. *
  59. * @see com.vaadin.data.util.converter.Converter#getSourceType()
  60. */
  61. @Override
  62. public Class<MODEL> getModelType() {
  63. return realConverter.getPresentationType();
  64. }
  65. /*
  66. * (non-Javadoc)
  67. *
  68. * @see com.vaadin.data.util.converter.Converter#getTargetType()
  69. */
  70. @Override
  71. public Class<PRESENTATION> getPresentationType() {
  72. return realConverter.getModelType();
  73. }
  74. }