Skip to content

Package: TypeMap

TypeMap

nameinstructionbranchcomplexitylinemethod
TypeMap()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
get(String)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
register(String, Class)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2020 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.jsonld.deserialization.util;
16:
17: import java.util.*;
18:
19: /**
20: * Represents a map of type IRIs to their mapped Java classes.
21: * <p>
22: * Used by the deserialization when determining target class from JSON-LD object types.
23: * <p>
24: * This class is not synchronized, as it is expected that types will be registered by one thread once and then only queried.
25: */
26: public class TypeMap {
27:
28: private final Map<String, Set<Class<?>>> typeMap = new HashMap<>();
29:
30: public synchronized void register(String type, Class<?> cls) {
31:• if (!typeMap.containsKey(type)) {
32: // There will usually be only one class, so make the map as small as possible
33: typeMap.put(type, new HashSet<>(2));
34: }
35: typeMap.get(type).add(cls);
36: }
37:
38: public Set<Class<?>> get(String type) {
39: return typeMap.getOrDefault(type, Collections.emptySet());
40: }
41: }