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