Skip to content

Package: PluralAnnotationPropertyStrategy

PluralAnnotationPropertyStrategy

nameinstructionbranchcomplexitylinemethod
PluralAnnotationPropertyStrategy(EntityType, AbstractPluralAttribute, 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%
addValueFromAxiom(Axiom)
M: 0 C: 32
100%
M: 2 C: 4
67%
M: 2 C: 2
50%
M: 0 C: 6
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 4 C: 59
94%
M: 1 C: 11
92%
M: 1 C: 6
86%
M: 0 C: 13
100%
M: 0 C: 1
100%
createAssertion()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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%
lambda$buildAxiomValuesFromInstance$1(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.AbstractPluralAttribute;
19: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
20: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
21: import cz.cvut.kbss.ontodriver.model.Assertion;
22: import cz.cvut.kbss.ontodriver.model.Axiom;
23: import cz.cvut.kbss.ontodriver.model.NamedResource;
24: import cz.cvut.kbss.ontodriver.model.Value;
25:
26: import java.util.Collection;
27: import java.util.Objects;
28: import java.util.Set;
29: import java.util.function.Function;
30: import java.util.stream.Collectors;
31:
32: class PluralAnnotationPropertyStrategy<X> extends PluralDataPropertyStrategy<X> {
33:
34: PluralAnnotationPropertyStrategy(EntityType<X> et, AbstractPluralAttribute<? super X, ?, ?> att,
35: Descriptor attributeDescriptor, EntityMappingHelper mapper) {
36: super(et, att, attributeDescriptor, mapper);
37: }
38:
39: @Override
40: void addValueFromAxiom(Axiom<?> ax) {
41: final Object value = ax.getValue().getValue();
42:• if (isValidRange(value)) {
43: values.add(toAttributeValue(value));
44:• } else if (value instanceof NamedResource && IdentifierTransformer.isValidIdentifierType(elementType)) {
45: values.add(IdentifierTransformer.transformToIdentifier(value, elementType));
46: }
47: }
48:
49: @Override
50: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
51: final Object value = extractFieldValueFromInstance(instance);
52:• assert value instanceof Collection || value == null;
53: final Collection<?> valueCollection = (Collection<?>) value;
54:• if (valueCollection == null || valueCollection.isEmpty()) {
55: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext());
56: } else {
57: final Function<Object, Value<?>> mapper;
58:• if (IdentifierTransformer.isValidIdentifierType(elementType) && !elementType
59:• .isAssignableFrom(String.class)) {
60: mapper = v -> new Value<>(NamedResource.create(IdentifierTransformer.valueAsUri(v)));
61: } else {
62: mapper = v -> new Value<>(toAxiomValue(v));
63: }
64: final Set<Value<?>> assertionValues =
65: valueCollection.stream().filter(Objects::nonNull).map(mapper).collect(Collectors.toSet());
66: valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext());
67: }
68: }
69:
70: @Override
71: Assertion createAssertion() {
72: return Assertion
73: .createAnnotationPropertyAssertion(attribute.getIRI().toURI(), getLanguage(), attribute.isInferred());
74: }
75: }