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(Object)
M: 0 C: 21
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
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) 2017 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(Object value) {
45: final String id = value.toString();
46:• final Class<?> targetType = targetField != null ? targetField.getType() : owner.getItemType();
47: this.instance = (T) transformToTargetType(id, targetType);
48: }
49:
50: private Object transformToTargetType(String id, Class<?> targetType) {
51: return DataTypeTransformer.transformValue(id, targetType);
52: }
53:
54: @Override
55: void close() {
56:• assert instance != null;
57:• if (targetField != null) {
58: owner.setFieldValue(targetField, instance);
59: } else {
60: owner.addItem(instance);
61: }
62: }
63:
64: @Override
65: boolean isPropertyMapped(String property) {
66: return property.equals(JsonLd.ID);
67: }
68:
69: @Override
70: boolean supports(String property) {
71: return isPropertyMapped(property);
72: }
73:
74: @Override
75: Class<T> getInstanceType() {
76: return null;
77: }
78:
79: @Override
80: Field getFieldForProperty(String property) {
81: return null;
82: }
83:
84: @Override
85: boolean hasPropertiesField() {
86: return false;
87: }
88: }