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