1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package pl.edu.agh.cast.data.converter;
19
20 import java.util.Collections;
21 import java.util.LinkedList;
22 import java.util.List;
23
24 import pl.edu.agh.cast.Activator;
25 import pl.edu.agh.cast.data.model.Type;
26
27
28
29
30
31
32 public final class ConverterRegistry {
33
34 private List<ConverterReference> converterReferences;
35
36
37
38
39
40
41
42
43 private static final class ConverterRegistryHolder {
44 private static final ConverterRegistry INSTANCE = createInstance();
45 }
46
47 private static ConverterRegistry createInstance() {
48 return new ConverterRegistry();
49 }
50
51 public static ConverterRegistry getInstance() {
52 return ConverterRegistryHolder.INSTANCE;
53 }
54
55
56
57 private ConverterRegistry() {
58 converterReferences = Activator.getDataSetConverterReferences();
59 }
60
61
62
63
64
65
66
67
68 public List<ConverterReference> getMatchingConverters(List<Type> types) {
69 List<ConverterReference> matchingReferences = new LinkedList<ConverterReference>();
70
71 for (ConverterReference converterReference : converterReferences) {
72 if (isMatching(converterReference.getSpecification(), types)) {
73 matchingReferences.add(converterReference);
74 }
75 }
76
77 return matchingReferences;
78 }
79
80
81
82
83
84
85
86
87 public List<ConverterReference> getMatchingConverters(Type type) {
88 return getMatchingConverters(Collections.singletonList(type));
89 }
90
91
92
93
94
95
96
97
98
99
100 public static boolean isMatching(ConverterSpecification spec, List<Type> types) {
101 return types.size() == 1 && spec.getInputEntries().size() == 1
102 && types.get(0).equals(spec.getInputEntries().get(0).getType());
103 }
104
105 }