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(Object)
M: 0 C: 6
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$extractValues$1(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.Set;
28:
29: class SimpleSetPropertyStrategy<X> extends PluralObjectPropertyStrategy<X> {
30:
31: SimpleSetPropertyStrategy(EntityType<X> et, Attribute<? super X, ?> att, Descriptor descriptor,
32: EntityMappingHelper mapper) {
33: super(et, att, descriptor, mapper);
34: }
35:
36: @Override
37: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) throws IllegalAccessException {
38: final Object value = extractFieldValueFromInstance(instance);
39:• assert value instanceof Collection || value == null;
40: final Collection<?> valueCollection = (Collection<?>) value;
41: extractValues(valueCollection, valueBuilder);
42: }
43:
44: private <T> void extractValues(Collection<T> valueCollection, AxiomValueGatherer valueBuilder) {
45:• if (valueCollection == null) {
46: valueBuilder.addValue(createAssertion(), Value.nullValue(), getAttributeContext());
47: return;
48: }
49: final Set<Value<?>> assertionValues = new HashSet<>(valueCollection.size());
50:• if (IdentifierTransformer.isValidIdentifierType(pluralAtt.getBindableJavaType())) {
51:• valueCollection.stream().filter(item -> item != null).forEach(item -> assertionValues
52: .add(new Value<>(NamedResource.create(IdentifierTransformer.valueAsUri(item)))));
53: } else {
54: final EntityType<T> et = (EntityType<T>) mapper.getEntityType(pluralAtt.getBindableJavaType());
55:• for (T val : valueCollection) {
56:• if (val == null) {
57: continue;
58: }
59: final URI id = resolveValueIdentifier(val, et);
60: cascadeResolver.resolveFieldCascading(attribute, val, getAttributeContext());
61: assertionValues.add(new Value<>(NamedResource.create(id)));
62: }
63: }
64: valueBuilder.addValues(createAssertion(), assertionValues, getAttributeContext());
65: }
66: }