1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.util.converter;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashSet;
|
13
|
import java.util.List;
|
14
|
import java.util.Locale;
|
15
|
import java.util.Set;
|
16
|
|
17
|
import com.vaadin.data.util.converter.Converter;
|
18
|
|
19
|
/**
|
20
|
* @author a.kohlbecker
|
21
|
* @since Jun 7, 2017
|
22
|
*
|
23
|
*/
|
24
|
public final class SetToListConverter<V> implements Converter<List<V>, Set<V>> {
|
25
|
|
26
|
private static final long serialVersionUID = -4453200532452354378L;
|
27
|
|
28
|
@Override
|
29
|
public Set<V> convertToModel(List<V> value, Class<? extends Set<V>> targetType, Locale locale)
|
30
|
throws com.vaadin.data.util.converter.Converter.ConversionException {
|
31
|
if(value != null){
|
32
|
Set<V> set = new HashSet<>(value.size());
|
33
|
set.addAll(value);
|
34
|
return set;
|
35
|
}
|
36
|
return null;
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
public List<V> convertToPresentation(Set<V> value, Class<? extends List<V>> targetType, Locale locale)
|
41
|
throws com.vaadin.data.util.converter.Converter.ConversionException {
|
42
|
if(value != null){
|
43
|
List<V> list = new ArrayList<V>(value.size());
|
44
|
list.addAll(value);
|
45
|
return list;
|
46
|
}
|
47
|
return null;
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public Class<Set<V>> getModelType() {
|
52
|
return ((Class)Set.class);
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public Class<List<V>> getPresentationType() {
|
57
|
return ((Class)List.class);
|
58
|
}
|
59
|
}
|