Skip to content

Package: SimpleListIterator

SimpleListIterator

nameinstructionbranchcomplexitylinemethod
SimpleListIterator(SimpleListDescriptor, StorageConnector)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
nextAxiom()
M: 0 C: 32
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
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%
replace(Resource)
M: 0 C: 73
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 16
100%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.ontodriver.jena.list;
2:
3: import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor;
4: import cz.cvut.kbss.ontodriver.jena.connector.StorageConnector;
5: import cz.cvut.kbss.ontodriver.model.*;
6: import org.apache.jena.rdf.model.RDFNode;
7: import org.apache.jena.rdf.model.Resource;
8: import org.apache.jena.rdf.model.Statement;
9:
10: import java.net.URI;
11: import java.util.ArrayList;
12: import java.util.Collections;
13: import java.util.List;
14:
15: import static org.apache.jena.rdf.model.ResourceFactory.createStatement;
16:
17: class SimpleListIterator extends AbstractListIterator {
18:
19: SimpleListIterator(SimpleListDescriptor descriptor, StorageConnector connector) {
20: super(descriptor, connector);
21: }
22:
23: @Override
24: Axiom<NamedResource> nextAxiom() {
25: final NamedResource subject = NamedResource.create(currentNode.getURI());
26: final Assertion assertion = Assertion
27:• .createObjectPropertyAssertion(URI.create(first() ? hasList.getURI() : hasNext.getURI()), false);
28: final NamedResource value = nextValue();
29: return new AxiomImpl<>(subject, assertion, new Value<>(value));
30: }
31:
32: @Override
33: NamedResource nextValue() {
34: resolveNextListNode();
35: return NamedResource.create(currentNode.getURI());
36: }
37:
38: /**
39: * Replaces the current node with the specified replacement, connecting it into the list. Original links to the current
40: * element are removed.
41: *
42: * @param replacement The replacement node
43: */
44: @Override
45: void replace(Resource replacement) {
46: removeWithoutReconnect();
47: final List<Statement> toAdd = new ArrayList<>(2);
48:• toAdd.add(createStatement(previousNode, index == 0 ? hasList : hasNext, replacement));
49:• if (hasNext()) {
50: verifySuccessorCount();
51: final RDFNode nextNode = cursor.iterator().next().getObject();
52: remove(currentNode, hasNext, nextNode);
53:• if (!nextNode.equals(replacement)) {
54: final Statement linkToNext = createStatement(replacement, hasNext, nextNode);
55: toAdd.add(linkToNext);
56: this.cursor = Collections.singleton(linkToNext);
57: } else {
58: moveCursor(replacement);
59: }
60: }
61: this.currentNode = replacement;
62: connector.add(toAdd, context);
63: }
64: }