Skip to content

Package: InstanceContext

InstanceContext

nameinstructionbranchcomplexitylinemethod
InstanceContext(Object, Map)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addItem(Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getFieldForProperty(String)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getInstance()
M: 0 C: 3
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: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getItemType()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isPropertyMapped(String)
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setFieldValue(Field, Object)
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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 java.lang.reflect.Field;
18: import java.util.Map;
19:
20: abstract class InstanceContext<T> {
21:
22: final T instance;
23:
24: final Map<String, Object> knownInstances;
25:
26: InstanceContext(T instance, Map<String, Object> knownInstances) {
27: this.instance = instance;
28: this.knownInstances = knownInstances;
29: }
30:
31: T getInstance() {
32: return instance;
33: }
34:
35: @SuppressWarnings("unchecked")
36: Class<T> getInstanceType() {
37: return (Class<T>) instance.getClass();
38: }
39:
40: // These methods are intended for overriding, because the behaviour is supported only by some context implementations
41:
42: /**
43: * Gets a Java field mapped by the specified property.
44: * <p>
45: * This applies to singular object contexts only.
46: *
47: * @param property Property IRI
48: * @return Field mapped by the specified property. Can be {@code null}
49: */
50: Field getFieldForProperty(String property) {
51: throw new UnsupportedOperationException("Not supported by this type of instance context.");
52: }
53:
54: /**
55: * Sets value of the specified field on the instance represented by this context
56: *
57: * @param field The field to set
58: * @param value The value to set
59: */
60: void setFieldValue(Field field, Object value) {
61: throw new UnsupportedOperationException("Not supported by this type of instance context.");
62: }
63:
64: /**
65: * Adds item to the collection represented by this context.
66: *
67: * @param item Item to add
68: */
69: void addItem(Object item) {
70: throw new UnsupportedOperationException("Not supported by this type of instance context.");
71: }
72:
73: /**
74: * Gets type of the element type of a collection represented by this context.
75: *
76: * @return Collection element type
77: */
78: Class<?> getItemType() {
79: throw new UnsupportedOperationException("Not supported by this type of instance context.");
80: }
81:
82: /**
83: * Whether the specified property is mapped by a field in this context.
84: * <p>
85: * Note that if the context represents an instance with a {@link cz.cvut.kbss.jopa.model.annotations.Properties}
86: * field, every property is considered mapped
87: *
88: * @param property The property to check
89: * @return {@code true} if a field mapping the property exists in this context, {@code false} otherwise
90: */
91: boolean isPropertyMapped(String property) {
92: // Default behaviour
93: return false;
94: }
95: }