Skip to content

Package: AbstractSesameIterator

AbstractSesameIterator

nameinstructionbranchcomplexitylinemethod
AbstractSesameIterator(ListDescriptor, Connector, ValueFactory)
M: 0 C: 41
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
checkNodeIsResource(Statement)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
checkSuccessorMax(Collection, IRI)
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%
createAxiom(Resource, Assertion, Resource)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
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.ontodriver.sesame;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
18: import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException;
19: import cz.cvut.kbss.ontodriver.model.*;
20: import cz.cvut.kbss.ontodriver.sesame.connector.Connector;
21: import cz.cvut.kbss.ontodriver.sesame.util.SesameUtils;
22: import org.eclipse.rdf4j.model.IRI;
23: import org.eclipse.rdf4j.model.Resource;
24: import org.eclipse.rdf4j.model.Statement;
25: import org.eclipse.rdf4j.model.ValueFactory;
26:
27: import java.util.Collection;
28: import java.util.HashSet;
29:
30: abstract class AbstractSesameIterator implements SesameIterator {
31:
32: protected final Resource listOwner;
33: protected final IRI hasListProperty;
34: protected final IRI hasNextProperty;
35: protected final IRI context;
36: protected final boolean includeInferred;
37:
38: protected final Connector connector;
39: protected final ValueFactory vf;
40:
41: public AbstractSesameIterator(ListDescriptor listDescriptor, Connector connector, ValueFactory vf) {
42: this.listOwner = SesameUtils.toSesameIri(listDescriptor.getListOwner().getIdentifier(), vf);
43: this.hasListProperty = SesameUtils.toSesameIri(listDescriptor.getListProperty()
44: .getIdentifier(), vf);
45: this.hasNextProperty = SesameUtils.toSesameIri(
46: listDescriptor.getNextNode().getIdentifier(), vf);
47: this.context = SesameUtils.toSesameIri(listDescriptor.getContext(), vf);
48: this.includeInferred = listDescriptor.getListProperty().isInferred();
49: this.connector = connector;
50: this.vf = vf;
51: }
52:
53: protected void checkSuccessorMax(Collection<Statement> stmts, IRI property) {
54: // We don't mind the same statement multiple times, it could have been added during transaction
55:• if (new HashSet<>(stmts).size() > 1) {
56: throw new IntegrityConstraintViolatedException(
57: "Invalid number of values found for assertion " + property
58: + ". Expected 1, got " + stmts.size());
59: }
60: }
61:
62: protected void checkNodeIsResource(Statement stmt) {
63:• if (!(stmt.getObject() instanceof Resource)) {
64: throw new IntegrityConstraintViolatedException(
65: "Invalid property value. Expected object property value, got literal.");
66: }
67: }
68:
69: protected Axiom<NamedResource> createAxiom(Resource subject, Assertion assertion, Resource value) {
70: final NamedResource subjectRes = NamedResource.create(subject.stringValue());
71: return new AxiomImpl<>(subjectRes, assertion, new Value<>(NamedResource.create(value.stringValue())));
72: }
73: }