Skip to content

Package: ListPropertyStrategy

ListPropertyStrategy

nameinstructionbranchcomplexitylinemethod
ListPropertyStrategy(EntityType, ListAttribute, Descriptor, EntityMappingHelper)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
addListElementsToListValueDescriptor(ListValueDescriptor, List)
M: 0 C: 56
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 15
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 4 C: 17
81%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 4
100%
M: 0 C: 1
100%
lambda$addListElementsToListValueDescriptor$0(Object)
M: 0 C: 6
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$addListElementsToListValueDescriptor$1(ListValueDescriptor, Object)
M: 0 C: 6
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) 2016 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.jopa.oom;
16:
17: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
18: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
19: import cz.cvut.kbss.jopa.model.metamodel.ListAttribute;
20: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
21: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
22: import cz.cvut.kbss.ontodriver.descriptor.ListValueDescriptor;
23: import cz.cvut.kbss.ontodriver.model.Axiom;
24: import cz.cvut.kbss.ontodriver.model.NamedResource;
25:
26: import java.net.URI;
27: import java.util.List;
28:
29: abstract class ListPropertyStrategy<L extends ListDescriptor, V extends ListValueDescriptor, X>
30: extends PluralObjectPropertyStrategy<X> {
31:
32: final ListAttribute<? super X, ?> listAttribute;
33:
34: public ListPropertyStrategy(EntityType<X> et, ListAttribute<? super X, ?> att, Descriptor descriptor,
35: EntityMappingHelper mapper) {
36: super(et, att, descriptor, mapper);
37: this.listAttribute = att;
38: }
39:
40: @Override
41: protected void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder)
42: throws IllegalAccessException {
43: final Object value = extractFieldValueFromInstance(instance);
44:• assert value instanceof List || value == null;
45: extractListValues((List<?>) value, instance, valueBuilder);
46: }
47:
48: <K> void addListElementsToListValueDescriptor(ListValueDescriptor listDescriptor, List<K> list) {
49:• if (list == null) {
50: return;
51: }
52:• if (IdentifierTransformer.isValidIdentifierType(pluralAtt.getBindableJavaType())) {
53:• list.stream().filter(item -> item != null)
54: .forEach(item -> listDescriptor.addValue(NamedResource.create(IdentifierTransformer.valueAsUri(item))));
55: } else {
56: final Class<K> elemType = (Class<K>) listAttribute.getBindableJavaType();
57: final EntityType<K> valueType = mapper.getEntityType(elemType);
58:• for (K item : list) {
59:• if (item == null) {
60: continue;
61: }
62: final URI itemUri = resolveValueIdentifier(item, valueType);
63: cascadeResolver.resolveFieldCascading(pluralAtt, item, getAttributeContext());
64: listDescriptor.addValue(NamedResource.create(itemUri));
65: }
66: }
67: }
68:
69: abstract L createListDescriptor(Axiom<?> ax);
70:
71: abstract V createListValueDescriptor(X instance);
72:
73: abstract <K> void extractListValues(List<K> list, X instance, AxiomValueGatherer valueBuilder);
74: }