Skip to content

Package: MappingJsonLdContext

MappingJsonLdContext

nameinstructionbranchcomplexitylinemethod
MappingJsonLdContext()
M: 0 C: 8
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
MappingJsonLdContext(JsonLdContext)
M: 4 C: 15
79%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 4
100%
M: 0 C: 1
100%
getContextNode()
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
getMappedTerm(String)
M: 0 C: 5
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: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
hasTermMapping(String)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
isCurrentEmpty()
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%
registerTermMapping(String, ObjectNode)
M: 11 C: 12
52%
M: 3 C: 1
25%
M: 2 C: 1
33%
M: 1 C: 3
75%
M: 0 C: 1
100%
registerTermMapping(String, String)
M: 0 C: 27
100%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 5
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.JsonLd;
21: import cz.cvut.kbss.jsonld.exception.AmbiguousTermMappingException;
22: import cz.cvut.kbss.jsonld.serialization.JsonNodeFactory;
23: import cz.cvut.kbss.jsonld.serialization.model.JsonNode;
24: import cz.cvut.kbss.jsonld.serialization.model.ObjectNode;
25:
26: import java.util.Optional;
27:
28: /**
29: * Represents the {@literal @context} JSON-LD attribute.
30: * <p>
31: * Note that this represents the JSON-LD 1.0 context, so no <a href="https://www.w3.org/TR/json-ld/#scoped-contexts">context
32: * scoping</a> is supported and attempting to register a different mapping for an already existing term will result in
33: * an {@link AmbiguousTermMappingException}.
34: */
35: public class MappingJsonLdContext implements JsonLdContext {
36:
37: private TermMappingHolder mappingHolder;
38:
39: public MappingJsonLdContext() {
40: this.mappingHolder = new EmbeddedTermMappingHolder();
41: }
42:
43: public MappingJsonLdContext(JsonLdContext parent) {
44:• assert parent instanceof MappingJsonLdContext;
45: this.mappingHolder = new WriteThroughTermMappingHolder(((MappingJsonLdContext) parent).mappingHolder);
46: }
47:
48: @Override
49: public void registerTermMapping(String term, String iri) {
50: final JsonNode value = JsonNodeFactory.createStringLiteralNode(term, iri);
51:• if (!mappingHolder.canRegisterTermMapping(term, value) && !mappingHolder.isRoot()) {
52: this.mappingHolder = new EmbeddedTermMappingHolder(mappingHolder);
53: }
54: mappingHolder.registerTermMapping(term, value);
55: }
56:
57: @Override
58: public void registerTermMapping(String term, ObjectNode mappedNode) {
59:• if (!mappingHolder.canRegisterTermMapping(term, mappedNode) && !mappingHolder.isRoot()) {
60: this.mappingHolder = new EmbeddedTermMappingHolder(mappingHolder);
61: }
62: mappingHolder.registerTermMapping(term, mappedNode);
63: }
64:
65: @Override
66: public Optional<JsonNode> getTermMapping(String term) {
67: return mappingHolder.getTermMapping(term);
68: }
69:
70: @Override
71: public boolean hasTermMapping(String term) {
72: return mappingHolder.hasTermMapping(term);
73: }
74:
75: @Override
76: public Optional<String> getMappedTerm(String iri) {
77: return mappingHolder.getMappedTerm(iri);
78: }
79:
80: @Override
81: public boolean isCurrentEmpty() {
82: return mappingHolder.isEmpty();
83: }
84:
85: @Override
86: public ObjectNode getContextNode() {
87: final ObjectNode node = new ObjectNode(JsonLd.CONTEXT);
88: mappingHolder.getMapping().values().forEach(node::addItem);
89: return node;
90: }
91: }