ref #6169 ToManyRelatedEntitiesComboboxSelect, CdmFilterablePagingProvider and CdmTit...
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / util / converter / SetToListConverter.java
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 extends Object> implements Converter<List<V>, Set<V>> {
25
26 private static final long serialVersionUID = -4453200532452354378L;
27
28 Class<Set<V>> modelType = (Class<Set<V>>) new HashSet<V>(0).getClass();
29
30 Class<List<V>> presentationType = (Class<List<V>>) new ArrayList<V>(0).getClass();
31
32 @Override
33 public Set<V> convertToModel(List<V> value, Class<? extends Set<V>> targetType, Locale locale)
34 throws com.vaadin.data.util.converter.Converter.ConversionException {
35 if(value != null){
36 Set<V> set = new HashSet<>(value.size());
37 set.addAll(value);
38 return set;
39 }
40 return null;
41 }
42
43 @Override
44 public List<V> convertToPresentation(Set<V> value, Class<? extends List<V>> targetType, Locale locale)
45 throws com.vaadin.data.util.converter.Converter.ConversionException {
46 if(value != null){
47 List<V> list = new ArrayList<V>(value.size());
48 list.addAll(value);
49 return list;
50 }
51 return null;
52 }
53
54 @Override
55 public Class<Set<V>> getModelType() {
56 return modelType;
57 }
58
59 @Override
60 public Class<List<V>> getPresentationType() {
61 return presentationType;
62 }
63 }