Skip to content

Package: TypeReferenceMap

TypeReferenceMap

nameinstructionbranchcomplexitylinemethod
TypeReferenceMap()
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%
addReference(Class, Class)
M: 0 C: 28
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
getReferringTypes(Class)
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /**
2: * Copyright (C) 2022 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.jopa.model;
16:
17: import java.util.*;
18:
19: /**
20: * Represents a map of references between types.
21: * <p>
22: * That is, it allows to get all entity classes which have attributes of the specified type.
23: */
24: public class TypeReferenceMap {
25:
26: private final Map<Class<?>, Set<Class<?>>> referenceMap = new HashMap<>();
27:
28: /**
29: * Registers reference relationships between the specified types.
30: *
31: * @param referencedType Type being referenced
32: * @param referringType Type referring to the referenced type
33: */
34: public void addReference(Class<?> referencedType, Class<?> referringType) {
35: Objects.requireNonNull(referencedType);
36: Objects.requireNonNull(referringType);
37:• if (!referenceMap.containsKey(referencedType)) {
38: referenceMap.put(referencedType, new HashSet<>());
39: }
40: referenceMap.get(referencedType).add(referringType);
41: }
42:
43: /**
44: * Gets the set of entity classes containing an attribute of the specified type.
45: *
46: * @param referencedType Type being referenced for which referees should be returned
47: * @return Set of referring classes, empty set if there are none
48: */
49: public Set<Class<?>> getReferringTypes(Class<?> referencedType) {
50: return Collections.unmodifiableSet(referenceMap.getOrDefault(referencedType, Collections.emptySet()));
51: }
52: }