Skip to content

Package: TypesContext

TypesContext

nameinstructionbranchcomplexitylinemethod
TypesContext(Collection, Map, Class, Class)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addItem(Object)
M: 4 C: 36
90%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 7
100%
M: 0 C: 1
100%
getItemType()
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%
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: * 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.common.BeanAnnotationProcessor;
18: import cz.cvut.kbss.jsonld.deserialization.util.DataTypeTransformer;
19:
20: import java.util.Collection;
21: import java.util.Map;
22: import java.util.Set;
23:
24: class TypesContext<T extends Collection<E>, E> extends InstanceContext<T> {
25:
26: private final Set<String> mappedTypes;
27: private final Class<E> elementType;
28:
29: TypesContext(T instance, Map<String, Object> knownInstances, Class<E> elementType, Class<?> ownerType) {
30: super(instance, knownInstances);
31: this.elementType = elementType;
32: this.mappedTypes = BeanAnnotationProcessor.getOwlClasses(ownerType);
33: }
34:
35: @Override
36: void addItem(Object item) {
37:• assert item instanceof String;
38:• if (mappedTypes.contains(item)) {
39: return;
40: }
41:• if (!elementType.isAssignableFrom(item.getClass())) {
42: instance.add(DataTypeTransformer.transformValue(item, elementType));
43: } else {
44: instance.add(elementType.cast(item));
45: }
46: }
47:
48: @Override
49: Class<?> getItemType() {
50: return elementType;
51: }
52: }