Skip to content

Package: SimpleSetPropertyStrategy

SimpleSetPropertyStrategy

nameinstructionbranchcomplexitylinemethod
SimpleSetPropertyStrategy(EntityType, Attribute, 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%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 4 C: 18
82%
M: 1 C: 3
75%
M: 1 C: 2
67%
M: 0 C: 5
100%
M: 0 C: 1
100%
extractValues(Collection, AxiomValueGatherer)
M: 0 C: 78
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 16
100%
M: 0 C: 1
100%
lambda$extractValues$0(Set, Object)
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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: *
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.Attribute;
19: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
20: import cz.cvut.kbss.jopa.utils.IdentifierTransformer;
21: import cz.cvut.kbss.ontodriver.model.NamedResource;
22: import cz.cvut.kbss.ontodriver.model.Value;
23:
24: import java.net.URI;
25: import java.util.Collection;
26: import java.util.HashSet;
27: import java.util.Objects;
28: import java.util.Set;
29:
30: class SimpleSetPropertyStrategy<X> extends PluralObjectPropertyStrategy<X> {
31:
32: SimpleSetPropertyStrategy(EntityType<X> et, Attribute<? super X, ?> att, Descriptor descriptor,
33: EntityMappingHelper mapper) {
34: super(et, att, descriptor, mapper);
35: }
36:
37: @Override
38: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) throws IllegalAccessException {
39: final Object value = extractFieldValueFromInstance(instance);
40:• assert value instanceof Collection || value == null;
41: final Collection<?> valueCollection = (Collection<?>) value;
42: extractValues(valueCollection, valueBuilder);
43: }
44:
45: private <T> void extractValues(Collection<T> valueCollection, AxiomValueGatherer valueBuilder) {
46:• if (valueCollection == null) {
47: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext());
48: return;
49: }
50: final Set<Value<?>> assertionValues = new HashSet<>(valueCollection.size());
51:• if (IdentifierTransformer.isValidIdentifierType(pluralAtt.getBindableJavaType())) {
52: valueCollection.stream().filter(Objects::nonNull).forEach(item -> assertionValues
53: .add(new Value<>(NamedResource.create(IdentifierTransformer.valueAsUri(item)))));
54: } else {
55: final EntityType<T> et = (EntityType<T>) mapper.getEntityType(pluralAtt.getBindableJavaType());
56:• for (T val : valueCollection) {
57:• if (val == null) {
58: continue;
59: }
60: final URI id = resolveValueIdentifier(val, et);
61: cascadeResolver.resolveFieldCascading(attribute, val, getAttributeContext());
62: assertionValues.add(new Value<>(NamedResource.create(id)));
63: }
64: }
65: valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext());
66: }
67: }