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