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