Skip to content

Package: PluralObjectPropertyStrategy

PluralObjectPropertyStrategy

nameinstructionbranchcomplexitylinemethod
PluralObjectPropertyStrategy(EntityType, Attribute, Descriptor, EntityMappingHelper)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
addValueFromAxiom(Axiom)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
buildInstanceFieldValue(Object)
M: 2 C: 10
83%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 2
100%
M: 0 C: 1
100%
createAssertion()
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%
initCollection()
M: 5 C: 20
80%
M: 1 C: 2
67%
M: 1 C: 2
67%
M: 1 C: 6
86%
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.model.metamodel.PluralAttribute;
21: import cz.cvut.kbss.ontodriver.exception.NotYetImplementedException;
22: import cz.cvut.kbss.ontodriver.model.Assertion;
23: import cz.cvut.kbss.ontodriver.model.Axiom;
24: import cz.cvut.kbss.ontodriver.model.NamedResource;
25:
26: import java.util.ArrayList;
27: import java.util.Collection;
28: import java.util.HashSet;
29:
30: abstract class PluralObjectPropertyStrategy<X> extends FieldStrategy<Attribute<? super X, ?>, X> {
31:
32: final PluralAttribute<? super X, ?, ?> pluralAtt;
33: private Collection<Object> values;
34:
35: public PluralObjectPropertyStrategy(EntityType<X> et, Attribute<? super X, ?> att,
36: Descriptor descriptor, EntityMappingHelper mapper) {
37: super(et, att, descriptor, mapper);
38: this.pluralAtt = (PluralAttribute<? super X, ?, ?>) attribute;
39: initCollection();
40: }
41:
42: private void initCollection() {
43:• switch (pluralAtt.getCollectionType()) {
44: case LIST:
45: this.values = new ArrayList<>();
46: break;
47: case COLLECTION:
48: case SET:
49: this.values = new HashSet<>();
50: break;
51: default:
52: throw new NotYetImplementedException("This type of collection is not supported yet.");
53: }
54: }
55:
56: @Override
57: void addValueFromAxiom(Axiom<?> ax) {
58: final NamedResource valueIdentifier = (NamedResource) ax.getValue().getValue();
59: final Object value = mapper.getEntityFromCacheOrOntology(pluralAtt.getBindableJavaType(),
60: valueIdentifier.getIdentifier(), attributeDescriptor);
61: values.add(value);
62:
63: }
64:
65: @Override
66: void buildInstanceFieldValue(Object instance) throws IllegalAccessException {
67:• setValueOnInstance(instance, values.isEmpty() ? null : values);
68: }
69:
70: @Override
71: Assertion createAssertion() {
72: return Assertion.createObjectPropertyAssertion(pluralAtt.getIRI().toURI(),
73: attribute.isInferred());
74: }
75: }