Skip to content

Package: DataPropertyFieldStrategy

DataPropertyFieldStrategy

nameinstructionbranchcomplexitylinemethod
DataPropertyFieldStrategy(EntityType, AbstractAttribute, Descriptor, EntityMappingHelper)
M: 0 C: 16
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
canBeConverted(Object)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
createAssertion()
M: 0 C: 13
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getLanguage()
M: 0 C: 24
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
isValidRange(Object)
M: 0 C: 16
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toAttributeValue(Object)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
toAxiomValue(Object)
M: 0 C: 5
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) 2020 Czech Technical University in Prague
3: * <p>
4: * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
5: * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
6: * version.
7: * <p>
8: * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
9: * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
10: * details. You should have received a copy of the GNU General Public License along with this program. If not, see
11: * <http://www.gnu.org/licenses/>.
12: */
13: package cz.cvut.kbss.jopa.oom;
14:
15: import cz.cvut.kbss.jopa.model.descriptors.Descriptor;
16: import cz.cvut.kbss.jopa.model.metamodel.AbstractAttribute;
17: import cz.cvut.kbss.jopa.model.metamodel.EntityType;
18: import cz.cvut.kbss.jopa.oom.converter.ConverterWrapper;
19: import cz.cvut.kbss.jopa.oom.converter.DefaultConverterWrapper;
20: import cz.cvut.kbss.ontodriver.model.Assertion;
21:
22: abstract class DataPropertyFieldStrategy<A extends AbstractAttribute<? super X, ?>, X> extends FieldStrategy<A, X> {
23:
24: private final ConverterWrapper<Object, Object> converter;
25:
26: DataPropertyFieldStrategy(EntityType<X> et, A att, Descriptor entityDescriptor,
27: EntityMappingHelper mapper) {
28: super(et, att, entityDescriptor, mapper);
29:• this.converter = att.getConverter() != null ? att.getConverter() : DefaultConverterWrapper.INSTANCE;
30: }
31:
32: boolean isValidRange(Object value) {
33:• return attribute.getJavaType().isAssignableFrom(value.getClass()) || canBeConverted(value);
34: }
35:
36: boolean canBeConverted(Object value) {
37: return converter.supportsAxiomValueType(value.getClass());
38: }
39:
40: Object toAttributeValue(Object value) {
41: return converter.convertToAttribute(value);
42: }
43:
44: Object toAxiomValue(Object value) {
45: return converter.convertToAxiomValue(value);
46: }
47:
48: String getLanguage() {
49:• if (attribute.isSimpleLiteral()) {
50: return null;
51: }
52: final Descriptor attDescriptor = entityDescriptor.getAttributeDescriptor(attribute);
53:• return attDescriptor.hasLanguage() ? attDescriptor.getLanguage() : attribute.getLanguage();
54: }
55:
56: @Override
57: Assertion createAssertion() {
58: return Assertion.createDataPropertyAssertion(attribute.getIRI().toURI(), getLanguage(), attribute.isInferred());
59: }
60: }