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%
addAxiomValue(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: 49
92%
M: 1 C: 7
88%
M: 1 C: 4
80%
M: 0 C: 13
100%
M: 0 C: 1
100%
buildAxiomsFromInstance(Object)
M: 6 C: 40
87%
M: 4 C: 4
50%
M: 3 C: 2
40%
M: 0 C: 10
100%
M: 0 C: 1
100%
buildInstanceFieldValue(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
hasValue()
M: 8 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
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$buildAxiomsFromInstance$0(NamedResource, Assertion, Object)
M: 0 C: 9
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: * JOPA
3: * Copyright (C) 2024 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.jopa.oom;
19:
20: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
21: import cz.cvut.kbss.jopa.model.metamodel.AbstractPluralAttribute;
22: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
23: import cz.cvut.kbss.jopa.utils.CollectionFactory;
24: import cz.cvut.kbss.jopa.utils.EntityPropertiesUtils;
25: import cz.cvut.kbss.ontodriver.model.*;
26:
27: import java.util.Collection;
28: import java.util.Collections;
29: import java.util.Objects;
30: import java.util.Set;
31: import java.util.stream.Collectors;
32:
33: class PluralDataPropertyStrategy<X> extends DataPropertyFieldStrategy<AbstractPluralAttribute<? super X, ?, ?>, X> {
34:
35: final Class<?> elementType;
36:
37: final Collection<Object> values;
38:
39: PluralDataPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att,
40: Descriptor attributeDescriptor, EntityMappingHelper mapper) {
41: super(et, att, attributeDescriptor, mapper);
42: this.values = CollectionFactory.createDefaultCollection(att.getCollectionType());
43: this.elementType = att.getElementType().getJavaType();
44: }
45:
46: @Override
47: void addAxiomValue(Axiom<?> ax) {
48: final Object value = ax.getValue().getValue();
49:• if (isValidRange(value)) {
50: this.values.add(toAttributeValue(value));
51: }
52: }
53:
54: @Override
55: boolean hasValue() {
56:• return !values.isEmpty();
57: }
58:
59: @Override
60: boolean isValidRange(Object value) {
61:• return elementType.isAssignableFrom(value.getClass()) || canBeConverted(value);
62: }
63:
64: @Override
65: void buildInstanceFieldValue(Object instance) {
66: setValueOnInstance(instance, values);
67: }
68:
69: @Override
70: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
71: final Object value = extractFieldValueFromInstance(instance);
72:• assert value instanceof Collection || value == null;
73: final Collection<?> valueCollection = (Collection<?>) value;
74:• if (valueCollection == null || valueCollection.isEmpty()) {
75: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeWriteContext());
76: } else {
77: final Set<Value<?>> assertionValues = valueCollection.stream()
78: .filter(Objects::nonNull)
79: .map(this::convertToAxiomValue)
80: .collect(Collectors.toSet());
81: valueBuilder.addValues(createAssertion(),
82: filterOutInferredValues(valueBuilder.getSubjectIdentifier(), assertionValues),
83: getAttributeWriteContext());
84: }
85: }
86:
87: @Override
88: Set<Axiom<?>> buildAxiomsFromInstance(X instance) {
89: final Object value = extractFieldValueFromInstance(instance);
90:• assert value instanceof Collection || value == null;
91: final Collection<?> valueCollection = (Collection<?>) value;
92:• if (valueCollection == null || valueCollection.isEmpty()) {
93: return Collections.emptySet();
94: } else {
95: final NamedResource subject = NamedResource.create(EntityPropertiesUtils.getIdentifier(instance, et));
96: final Assertion assertion = createAssertion();
97: return valueCollection.stream().filter(Objects::nonNull)
98: .map(v -> new AxiomImpl<>(subject, assertion, convertToAxiomValue(v)))
99: .collect(Collectors.toSet());
100: }
101: }
102: }