Skip to content

Package: EmbeddedTermMappingHolder

EmbeddedTermMappingHolder

nameinstructionbranchcomplexitylinemethod
EmbeddedTermMappingHolder()
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
EmbeddedTermMappingHolder(TermMappingHolder)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
canRegisterTermMapping(String, JsonNode)
M: 0 C: 2
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getMappedTerm(String)
M: 0 C: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
getMapping()
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%
getTermMapping(String)
M: 0 C: 17
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasTermMapping(String)
M: 0 C: 14
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasTermMapping(String, JsonNode)
M: 0 C: 17
100%
M: 0 C: 4
100%
M: 0 C: 3
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%
isRoot()
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
registerTermMapping(String, JsonNode)
M: 0 C: 38
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
verifyMappingUnique(String, JsonNode)
M: 0 C: 19
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JB4JSON-LD
3: * Copyright (C) 2023 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.serialization.context;
19:
20: import cz.cvut.kbss.jsonld.exception.AmbiguousTermMappingException;
21: import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
22:
23: import java.util.*;
24:
25: class EmbeddedTermMappingHolder extends TermMappingHolder {
26:
27: private final Map<String, JsonNode> mapping = new HashMap<>();
28:
29: EmbeddedTermMappingHolder() {
30: super(DummyTermMappingHolder.INSTANCE);
31: }
32:
33: EmbeddedTermMappingHolder(TermMappingHolder parentContext) {
34: super(parentContext);
35: }
36:
37: @Override
38: boolean canRegisterTermMapping(String term, JsonNode mappedNode) {
39: return true;
40: }
41:
42: @Override
43: void registerTermMapping(String term, JsonNode mappedNode) {
44: Objects.requireNonNull(term);
45: Objects.requireNonNull(mappedNode);
46:• if (parentContext.hasTermMapping(term, mappedNode)) {
47: // Already mapped in parent
48: return;
49: }
50:• if (!isRoot() && !parentContext.hasTermMapping(term)) {
51: parentContext.registerTermMapping(term, mappedNode);
52: } else {
53: verifyMappingUnique(term, mappedNode);
54: mapping.put(term, mappedNode);
55: }
56: }
57:
58: boolean isRoot() {
59:• return parentContext == DummyTermMappingHolder.INSTANCE;
60: }
61:
62: private void verifyMappingUnique(String term, JsonNode value) {
63:• if (mapping.containsKey(term) && !Objects.equals(mapping.get(term), value)) {
64: throw new AmbiguousTermMappingException("Context already contains mapping for term '" + term + "'.");
65: }
66: }
67:
68: @Override
69: public Map<String, JsonNode> getMapping() {
70: return Collections.unmodifiableMap(mapping);
71: }
72:
73: @Override
74: public Optional<JsonNode> getTermMapping(String term) {
75:• return mapping.containsKey(term) ? Optional.of(mapping.get(term)) : parentContext.getTermMapping(term);
76: }
77:
78: @Override
79: public boolean hasTermMapping(String term) {
80:• return mapping.containsKey(term) || parentContext.hasTermMapping(term);
81: }
82:
83: @Override
84: boolean hasTermMapping(String term, JsonNode mappedNode) {
85:• return mapping.containsKey(term) && mapping.get(term).equals(mappedNode);
86: }
87:
88: @Override
89: public Optional<String> getMappedTerm(String iri) {
90: final Optional<String> result = super.getMappedTerm(iri);
91:• if (result.isPresent()) {
92: return result;
93: }
94: return parentContext.getMappedTerm(iri);
95: }
96:
97: @Override
98: boolean isEmpty() {
99: return mapping.isEmpty();
100: }
101: }