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: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.oom;
14:
15: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
16: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
17: import cz.cvut.kbss.jopa.model.metamodel.ListAttribute;
18: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
19: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
20: import cz.cvut.kbss.ontodriver.descriptor.ListValueDescriptor;
21: import cz.cvut.kbss.ontodriver.model.Axiom;
22: import cz.cvut.kbss.ontodriver.model.NamedResource;
23:
24: import java.net.URI;
25: import java.util.List;
26:
27: abstract class ListPropertyStrategy<L extends ListDescriptor, V extends ListValueDescriptor, X>
28: extends PluralObjectPropertyStrategy<X> {
29:
30: final ListAttribute<? super X, ?> listAttribute;
31:
32: public ListPropertyStrategy(EntityType<X> et, ListAttribute<? super X, ?> att, Descriptor descriptor,
33: EntityMappingHelper mapper) {
34: super(et, att, descriptor, mapper);
35: this.listAttribute = att;
36: }
37:
38: @Override
39: protected void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder)
40: throws IllegalAccessException {
41: final Object value = extractFieldValueFromInstance(instance);
42:• assert value instanceof List || value == null;
43: extractListValues((List<?>) value, instance, valueBuilder);
44: }
45:
46: <K> void addListElementsToListValueDescriptor(ListValueDescriptor listDescriptor, List<K> list) {
47:• if (list == null) {
48: return;
49: }
50:• if (IdentifierTransformer.isValidIdentifierType(pluralAtt.getBindableJavaType())) {
51:• list.stream().filter(item -> item != null)
52: .forEach(item -> listDescriptor.addValue(NamedResource.create(IdentifierTransformer.valueAsUri(item))));
53: } else {
54: final Class<K> elemType = (Class<K>) listAttribute.getBindableJavaType();
55: final EntityType<K> valueType = mapper.getEntityType(elemType);
56:• for (K item : list) {
57:• if (item == null) {
58: continue;
59: }
60: final URI itemUri = resolveValueIdentifier(item, valueType);
61: cascadeResolver.resolveFieldCascading(pluralAtt, item, getAttributeContext());
62: listDescriptor.addValue(NamedResource.create(itemUri));
63: }
64: }
65: }
66:
67: abstract L createListDescriptor(Axiom<?> ax);
68:
69: abstract V createListValueDescriptor(X instance);
70:
71: abstract <K> void extractListValues(List<K> list, X instance, AxiomValueGatherer valueBuilder);
72: }