Skip to contentMethod: addDefaultConverters()
1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.model.metamodel;
14:
15: import cz.cvut.kbss.jopa.oom.converter.*;
16:
17: import java.time.Instant;
18: import java.time.LocalDate;
19: import java.time.LocalDateTime;
20: import java.time.ZonedDateTime;
21: import java.util.HashMap;
22: import java.util.Map;
23: import java.util.Optional;
24:
25: class Converters {
26:
27: private final Map<Class<?>, ConverterWrapper<?, ?>> defaultConverters;
28:
29: Converters() {
30: this.defaultConverters = new HashMap<>();
31: addDefaultConverters();
32: }
33:
34: private void addDefaultConverters() {
35: defaultConverters.put(LocalDate.class, new LocalDateConverter());
36: defaultConverters.put(LocalDateTime.class, new LocalDateTimeConverter());
37: defaultConverters.put(Instant.class, new InstantConverter());
38: defaultConverters.put(ZonedDateTime.class, new ZonedDateTimeConverter());
39: defaultConverters.put(Short.class, new ToShortConverter());
40: defaultConverters.put(Integer.class, new ToIntegerConverter());
41: defaultConverters.put(Long.class, new ToLongConverter());
42: defaultConverters.put(Float.class, new ToFloatConverter());
43: defaultConverters.put(Double.class, new ToDoubleConverter());
44: defaultConverters.put(Object.class, new ObjectConverter());
45: }
46:
47: Optional<ConverterWrapper<?, ?>> getConverter(Class<?> type) {
48: return Optional.ofNullable(defaultConverters.get(type));
49: }
50: }