Skip to content

Package: AbstractListIterator

AbstractListIterator

nameinstructionbranchcomplexitylinemethod
AbstractListIterator(ListDescriptor, Connector, ValueFactory)
M: 0 C: 47
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 11
100%
M: 0 C: 1
100%
checkObjectIsResource(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: 14
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
contexts()
M: 0 C: 9
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
icViolatedException(IRI, int)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.rdf4j.list;
19:
20: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
21: import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException;
22: import cz.cvut.kbss.ontodriver.rdf4j.connector.Connector;
23: import cz.cvut.kbss.ontodriver.rdf4j.util.Rdf4jUtils;
24: import cz.cvut.kbss.ontodriver.rdf4j.util.ValueConverter;
25: import org.eclipse.rdf4j.model.IRI;
26: import org.eclipse.rdf4j.model.Resource;
27: import org.eclipse.rdf4j.model.Statement;
28: import org.eclipse.rdf4j.model.ValueFactory;
29:
30: import java.util.Collection;
31: import java.util.Collections;
32: import java.util.HashSet;
33: import java.util.Set;
34:
35: abstract class AbstractListIterator<JT> implements ListIterator<JT> {
36:
37: protected final Resource listOwner;
38: protected final IRI hasListProperty;
39: protected final IRI hasNextProperty;
40: protected final IRI context;
41: protected final boolean includeInferred;
42:
43: protected final Connector connector;
44: protected final ValueFactory vf;
45:
46: protected final ValueConverter valueConverter;
47:
48: public AbstractListIterator(ListDescriptor listDescriptor, Connector connector, ValueFactory vf) {
49: this.listOwner = Rdf4jUtils.toRdf4jIri(listDescriptor.getListOwner().getIdentifier(), vf);
50: this.hasListProperty = Rdf4jUtils.toRdf4jIri(listDescriptor.getListProperty()
51: .getIdentifier(), vf);
52: this.hasNextProperty = Rdf4jUtils.toRdf4jIri(listDescriptor.getNextNode().getIdentifier(), vf);
53: this.context = Rdf4jUtils.toRdf4jIri(listDescriptor.getContext(), vf);
54: this.includeInferred = listDescriptor.getListProperty().isInferred();
55: this.connector = connector;
56: this.vf = vf;
57: this.valueConverter = new ValueConverter(vf);
58: }
59:
60: protected Set<IRI> contexts() {
61:• return context != null ? Collections.singleton(context) : Collections.emptySet();
62: }
63:
64: protected void checkSuccessorMax(Collection<Statement> stmts, IRI property) {
65: // We don't mind the same statement multiple times, it could have been added during transaction
66:• if (new HashSet<>(stmts).size() > 1) {
67: throw icViolatedException(property, stmts.size());
68: }
69: }
70:
71: protected IntegrityConstraintViolatedException icViolatedException(IRI property, int count) {
72: return new IntegrityConstraintViolatedException("Invalid number of values found for assertion " + property + ". Expected 1, got " + count);
73: }
74:
75: protected void checkObjectIsResource(Statement stmt) {
76:• if (!stmt.getObject().isResource()) {
77: throw new IntegrityConstraintViolatedException(
78: "Invalid property value. Expected object property value, got literal.");
79: }
80: }
81: }