Skip to content

Package: PluralDataPropertyStrategy

PluralDataPropertyStrategy

nameinstructionbranchcomplexitylinemethod
PluralDataPropertyStrategy(EntityType, AbstractPluralAttribute, Descriptor, EntityMappingHelper)
M: 0 C: 17
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addValueFromAxiom(Axiom)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 4 C: 45
92%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 11
100%
M: 0 C: 1
100%
buildInstanceFieldValue(Object)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
isValidRange(Object)
M: 0 C: 14
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$buildAxiomValuesFromInstance$0(Object)
M: 0 C: 7
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) 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.AbstractPluralAttribute;
20: import cz.cvut.kbss.jopa.utils.CollectionFactory;
21: import cz.cvut.kbss.ontodriver.model.Axiom;
22: import cz.cvut.kbss.ontodriver.model.Value;
23:
24: import java.util.Collection;
25: import java.util.Objects;
26: import java.util.Set;
27: import java.util.stream.Collectors;
28:
29: class PluralDataPropertyStrategy<X> extends DataPropertyFieldStrategy<AbstractPluralAttribute<? super X, ?, ?>, X> {
30:
31: final Class<?> elementType;
32:
33: final Collection<Object> values;
34:
35: PluralDataPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att,
36: Descriptor attributeDescriptor, EntityMappingHelper mapper) {
37: super(et, att, attributeDescriptor, mapper);
38: this.values = CollectionFactory.createDefaultCollection(att.getCollectionType());
39: this.elementType = att.getElementType().getJavaType();
40: }
41:
42: @Override
43: void addValueFromAxiom(Axiom<?> ax) {
44: final Object value = ax.getValue().getValue();
45:• if (isValidRange(value)) {
46: this.values.add(toAttributeValue(value));
47: }
48: }
49:
50: @Override
51: boolean isValidRange(Object value) {
52:• return elementType.isAssignableFrom(value.getClass()) || canBeConverted(value);
53: }
54:
55: @Override
56: void buildInstanceFieldValue(Object instance) {
57:• if (!values.isEmpty()) {
58: setValueOnInstance(instance, values);
59: }
60: }
61:
62: @Override
63: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
64: final Object value = extractFieldValueFromInstance(instance);
65:• assert value instanceof Collection || value == null;
66: final Collection<?> valueCollection = (Collection<?>) value;
67:• if (valueCollection == null || valueCollection.isEmpty()) {
68: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext());
69: } else {
70: final Set<Value<?>> assertionValues = valueCollection.stream()
71: .filter(Objects::nonNull)
72: .map(v -> new Value<>(toAxiomValue(v)))
73: .collect(Collectors.toSet());
74: valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext());
75: }
76: }
77: }