Skip to content

Package: ListPropertyStrategy

ListPropertyStrategy

nameinstructionbranchcomplexitylinemethod
ListPropertyStrategy(EntityType, ListAttributeImpl, Descriptor, EntityMappingHelper)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addItemsToDescriptor(ListValueDescriptor, List, EntityType)
M: 0 C: 9
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
addListElementsToListValueDescriptor(ListValueDescriptor, List)
M: 0 C: 32
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 9
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$addItemsToDescriptor$1(ListValueDescriptor, EntityType, Object)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$addListElementsToListValueDescriptor$0(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%
lambda$resolveUnpersistedItems$2(Object)
M: 0 C: 13
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
resolveUnpersistedItems(List)
M: 0 C: 21
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
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) 2020 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.ListAttributeImpl;
20: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
21: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
22: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
23: import cz.cvut.kbss.ontodriver.descriptor.ListValueDescriptor;
24: import cz.cvut.kbss.ontodriver.model.Axiom;
25: import cz.cvut.kbss.ontodriver.model.NamedResource;
26:
27: import java.util.Collections;
28: import java.util.List;
29: import java.util.Objects;
30: import java.util.stream.Collectors;
31:
32: abstract class ListPropertyStrategy<L extends ListDescriptor, V extends ListValueDescriptor, X>
33: extends PluralObjectPropertyStrategy<ListAttributeImpl<? super X, ?>, X> {
34:
35: ListPropertyStrategy(EntityType<X> et, ListAttributeImpl<? super X, ?> att, Descriptor descriptor,
36: EntityMappingHelper mapper) {
37: super(et, att, descriptor, mapper);
38: }
39:
40: @Override
41: protected void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
42: final Object value = extractFieldValueFromInstance(instance);
43:• assert value instanceof List || value == null;
44: extractListValues((List<?>) value, instance, valueBuilder);
45: }
46:
47: /**
48: * Adds elements of the list to the value descriptor.
49: */
50: <K> void addListElementsToListValueDescriptor(ListValueDescriptor listDescriptor, List<K> list) {
51:• if (list == null) {
52: return;
53: }
54:• if (IdentifierTransformer.isValidIdentifierType(attribute.getBindableJavaType())) {
55: list.stream().filter(Objects::nonNull)
56: .forEach(item -> listDescriptor.addValue(NamedResource.create(IdentifierTransformer.valueAsUri(item))));
57: } else {
58: final Class<?> elemType = attribute.getBindableJavaType();
59: final EntityType<?> valueType = mapper.getEntityType(elemType);
60: addItemsToDescriptor(listDescriptor, list, valueType);
61: }
62: }
63:
64: static void addItemsToDescriptor(ListValueDescriptor listDescriptor, List<?> list, EntityType<?> valueType) {
65: list.stream().filter(Objects::nonNull).forEach(item -> listDescriptor
66: .addValue(NamedResource.create(EntityPropertiesUtils.getIdentifier(item, valueType))));
67: }
68:
69: <K> List<K> resolveUnpersistedItems(List<K> list) {
70:• if (list == null) {
71: return Collections.emptyList();
72: }
73:• if (IdentifierTransformer.isValidIdentifierType(attribute.getBindableJavaType())) {
74: return Collections.emptyList();
75: } else {
76:• return list.stream().filter(item -> item != null && !referenceSavingResolver
77:• .shouldSaveReferenceToItem(item, getAttributeValueContext())).collect(Collectors.toList());
78: }
79: }
80:
81: abstract L createListDescriptor(Axiom<?> ax);
82:
83: abstract V createListValueDescriptor(X instance);
84:
85: abstract <K> void extractListValues(List<K> list, X instance, AxiomValueGatherer valueBuilder);
86: }