Skip to content

Package: NodeReferenceContext

NodeReferenceContext

nameinstructionbranchcomplexitylinemethod
NodeReferenceContext(InstanceContext, Field, Map)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
NodeReferenceContext(InstanceContext, Map)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
close()
M: 4 C: 21
84%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 5
100%
M: 0 C: 1
100%
getFieldForProperty(String)
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%
getInstanceType()
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%
hasPropertiesField()
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%
isPropertyMapped(String)
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%
setIdentifierValue(String)
M: 0 C: 18
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
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%
supports(String)
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%
transformToTargetType(String, Class)
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%

Coverage

1: /**
2: * Copyright (C) 2020 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.jsonld.deserialization;
16:
17: import cz.cvut.kbss.jsonld.JsonLd;
18: import cz.cvut.kbss.jsonld.deserialization.util.DataTypeTransformer;
19:
20: import java.lang.reflect.Field;
21: import java.util.Map;
22:
23: /**
24: * Represents deserialization context of a plain identifier object property.
25: */
26: class NodeReferenceContext<T> extends InstanceContext<T> {
27:
28: private final InstanceContext<?> owner;
29: private final Field targetField;
30:
31: NodeReferenceContext(InstanceContext<?> owner, Field targetField, Map<String, Object> knownInstances) {
32: super(null, knownInstances);
33: this.owner = owner;
34: this.targetField = targetField;
35: }
36:
37: NodeReferenceContext(InstanceContext<?> owner, Map<String, Object> knownInstances) {
38: super(null, knownInstances);
39: this.owner = owner;
40: this.targetField = null;
41: }
42:
43: @Override
44: void setIdentifierValue(String value) {
45:• final Class<?> targetType = targetField != null ? targetField.getType() : owner.getItemType();
46: this.instance = (T) transformToTargetType(value, targetType);
47: }
48:
49: private Object transformToTargetType(String id, Class<?> targetType) {
50: return DataTypeTransformer.transformValue(id, targetType);
51: }
52:
53: @Override
54: void close() {
55:• assert instance != null;
56:• if (targetField != null) {
57: owner.setFieldValue(targetField, instance);
58: } else {
59: owner.addItem(instance);
60: }
61: }
62:
63: @Override
64: boolean isPropertyMapped(String property) {
65: return property.equals(JsonLd.ID);
66: }
67:
68: @Override
69: boolean supports(String property) {
70: return isPropertyMapped(property);
71: }
72:
73: @Override
74: Class<T> getInstanceType() {
75: return null;
76: }
77:
78: @Override
79: Field getFieldForProperty(String property) {
80: return null;
81: }
82:
83: @Override
84: boolean hasPropertiesField() {
85: return false;
86: }
87: }