Package: AbstractListIterator
AbstractListIterator
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
AbstractListIterator(ListDescriptor, Connector, ValueFactory) |
|
|
|
|
|
||||||||||||||||||||
checkNodeIsResource(Statement) |
|
|
|
|
|
||||||||||||||||||||
checkSuccessorMax(Collection, IRI) |
|
|
|
|
|
||||||||||||||||||||
contexts() |
|
|
|
|
|
||||||||||||||||||||
createAxiom(Resource, Assertion, Resource) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2022 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.rdf4j;
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.rdf4j.connector.Connector;
21: import cz.cvut.kbss.ontodriver.rdf4j.util.Rdf4jUtils;
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.Collections;
29: import java.util.HashSet;
30: import java.util.Set;
31:
32: abstract class AbstractListIterator implements ListIterator {
33:
34: protected final Resource listOwner;
35: protected final IRI hasListProperty;
36: protected final IRI hasNextProperty;
37: protected final IRI context;
38: protected final boolean includeInferred;
39:
40: protected final Connector connector;
41: protected final ValueFactory vf;
42:
43: public AbstractListIterator(ListDescriptor listDescriptor, Connector connector, ValueFactory vf) {
44: this.listOwner = Rdf4jUtils.toRdf4jIri(listDescriptor.getListOwner().getIdentifier(), vf);
45: this.hasListProperty = Rdf4jUtils.toRdf4jIri(listDescriptor.getListProperty()
46: .getIdentifier(), vf);
47: this.hasNextProperty = Rdf4jUtils.toRdf4jIri(listDescriptor.getNextNode().getIdentifier(), vf);
48: this.context = Rdf4jUtils.toRdf4jIri(listDescriptor.getContext(), vf);
49: this.includeInferred = listDescriptor.getListProperty().isInferred();
50: this.connector = connector;
51: this.vf = vf;
52: }
53:
54: protected Set<IRI> contexts() {
55:• return context != null ? Collections.singleton(context) : Collections.emptySet();
56: }
57:
58: protected void checkSuccessorMax(Collection<Statement> stmts, IRI property) {
59: // We don't mind the same statement multiple times, it could have been added during transaction
60:• if (new HashSet<>(stmts).size() > 1) {
61: throw new IntegrityConstraintViolatedException(
62: "Invalid number of values found for assertion " + property
63: + ". Expected 1, got " + stmts.size());
64: }
65: }
66:
67: protected void checkNodeIsResource(Statement stmt) {
68:• if (!(stmt.getObject() instanceof Resource)) {
69: throw new IntegrityConstraintViolatedException(
70: "Invalid property value. Expected object property value, got literal.");
71: }
72: }
73:
74: protected Axiom<NamedResource> createAxiom(Resource subject, Assertion assertion, Resource value) {
75: final NamedResource subjectRes = NamedResource.create(subject.stringValue());
76: return new AxiomImpl<>(subjectRes, assertion, new Value<>(NamedResource.create(value.stringValue())));
77: }
78: }