Skip to content

Package: SingularDataPropertyStrategy

SingularDataPropertyStrategy

nameinstructionbranchcomplexitylinemethod
SingularDataPropertyStrategy(EntityType, AbstractAttribute, 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: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
buildAxiomValuesFromInstance(Object, AxiomValueGatherer)
M: 0 C: 23
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
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%
verifyCardinalityConstraint(NamedResource)
M: 0 C: 25
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
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.exceptions.CardinalityConstraintViolatedException;
18: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
19: import cz.cvut.kbss.jopa.model.metamodel.AbstractAttribute;
20: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
21: import cz.cvut.kbss.ontodriver.model.Axiom;
22: import cz.cvut.kbss.ontodriver.model.NamedResource;
23: import cz.cvut.kbss.ontodriver.model.Value;
24:
25: class SingularDataPropertyStrategy<X> extends DataPropertyFieldStrategy<AbstractAttribute<? super X, ?>, X> {
26:
27: Object value;
28:
29: SingularDataPropertyStrategy(EntityType<X> et, AbstractAttribute<? super X, ?> att,
30: Descriptor descriptor, EntityMappingHelper mapper) {
31: super(et, att, descriptor, mapper);
32: }
33:
34: @Override
35: void addValueFromAxiom(Axiom<?> ax) {
36: final Object val = ax.getValue().getValue();
37:• if (!isValidRange(val)) {
38: return;
39: }
40: verifyCardinalityConstraint(ax.getSubject());
41: this.value = toAttributeValue(val);
42: }
43:
44: void verifyCardinalityConstraint(NamedResource subject) {
45:• if (value != null) {
46: throw new CardinalityConstraintViolatedException(
47: "Expected single value of attribute " + attribute.getName() + " of instance " + subject +
48: ", but got multiple");
49: }
50: }
51:
52: @Override
53: void buildInstanceFieldValue(Object entity) {
54: setValueOnInstance(entity, value);
55: }
56:
57: @Override
58: void buildAxiomValuesFromInstance(X instance, AxiomValueGatherer valueBuilder) {
59: final Object extractedValue = toAxiomValue(extractFieldValueFromInstance(instance));
60:
61:• final Value<?> val = extractedValue != null ? new Value<>(extractedValue) : Value.nullValue();
62: valueBuilder.addValue(createAssertion(), val, getAttributeContext());
63: }
64: }