Skip to content

Package: ReferencedListIterator

ReferencedListIterator

nameinstructionbranchcomplexitylinemethod
ReferencedListIterator(ReferencedListDescriptor, StorageConnector)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
nextAxiom()
M: 0 C: 19
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
nextValue()
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
removeWithoutReconnect()
M: 0 C: 10
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
replace(Resource)
M: 0 C: 22
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
resolveNodeContent()
M: 4 C: 28
88%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 0 C: 5
100%
M: 0 C: 1
100%
static {...}
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
verifyContentValueCount(Collection)
M: 0 C: 36
100%
M: 0 C: 4
100%
M: 0 C: 3
100%
M: 0 C: 6
100%
M: 0 C: 1
100%

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.jena.list;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
18: import cz.cvut.kbss.ontodriver.exception.IntegrityConstraintViolatedException;
19: import cz.cvut.kbss.ontodriver.jena.connector.StorageConnector;
20: import cz.cvut.kbss.ontodriver.model.*;
21: import org.apache.jena.rdf.model.Property;
22: import org.apache.jena.rdf.model.Resource;
23: import org.apache.jena.rdf.model.Statement;
24:
25: import java.util.Collection;
26: import java.util.Collections;
27:
28: import static org.apache.jena.rdf.model.ResourceFactory.createProperty;
29: import static org.apache.jena.rdf.model.ResourceFactory.createStatement;
30:
31: class ReferencedListIterator extends AbstractListIterator {
32:
33: private final Property hasContent;
34: private final Assertion hasContentAssertion;
35:
36: ReferencedListIterator(ReferencedListDescriptor descriptor, StorageConnector connector) {
37: super(descriptor, connector);
38: this.hasContentAssertion = descriptor.getNodeContent();
39: this.hasContent = createProperty(hasContentAssertion.getIdentifier().toString());
40: }
41:
42: @Override
43: Axiom<NamedResource> nextAxiom() {
44: final NamedResource value = nextValue();
45: final NamedResource node = NamedResource.create(currentNode.getURI());
46: return new AxiomImpl<>(node, hasContentAssertion, new Value<>(value));
47: }
48:
49: @Override
50: NamedResource nextValue() {
51: resolveNextListNode();
52: return NamedResource.create(resolveNodeContent().getURI());
53: }
54:
55: private Resource resolveNodeContent() {
56: final Collection<Statement> contentStatements;
57: contentStatements = connector.find(currentNode, hasContent, null, contexts());
58: verifyContentValueCount(contentStatements);
59: final Statement statement = contentStatements.iterator().next();
60:• assert statement.getObject().isResource();
61: return statement.getObject().asResource();
62: }
63:
64: private void verifyContentValueCount(Collection<Statement> contentStatements) {
65:• if (contentStatements.isEmpty()) {
66: throw new IntegrityConstraintViolatedException("No content found for list node " + currentNode.getURI());
67: }
68:• if (contentStatements.size() > 1) {
69: throw new IntegrityConstraintViolatedException(
70: "Encountered multiple content values of list node " + currentNode.getURI());
71: }
72: }
73:
74: @Override
75: void removeWithoutReconnect() {
76: super.removeWithoutReconnect();
77: remove(currentNode, hasContent, null);
78: }
79:
80: @Override
81: void replace(Resource replacement) {
82: remove(currentNode, hasContent, null);
83: final Statement toAdd = createStatement(currentNode, hasContent, replacement);
84: connector.add(Collections.singletonList(toAdd), context);
85: }
86: }