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