Package: ReferencedListHandler
ReferencedListHandler
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ReferencedListHandler(StorageConnector) |
|
|
|
|
|
||||||||||||||||||||
appendNewNodes(ReferencedListValueDescriptor, int, Resource) |
|
|
|
|
|
||||||||||||||||||||
appendNode(Resource, NamedResource, Property, Property, String, List) |
|
|
|
|
|
||||||||||||||||||||
generateNewListNode(URI, String) |
|
|
|
|
|
||||||||||||||||||||
iterator(ReferencedListDescriptor) |
|
|
|
|
|
||||||||||||||||||||
iterator(ReferencedListValueDescriptor) |
|
|
|
|
|
||||||||||||||||||||
static {...} |
|
|
|
|
|
Coverage
1: package cz.cvut.kbss.ontodriver.jena.list;
2:
3: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
4: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListValueDescriptor;
5: import cz.cvut.kbss.ontodriver.jena.connector.StorageConnector;
6: import cz.cvut.kbss.ontodriver.model.NamedResource;
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.net.URI;
12: import java.util.ArrayList;
13: import java.util.Collection;
14: import java.util.List;
15:
16: import static org.apache.jena.rdf.model.ResourceFactory.*;
17:
18: class ReferencedListHandler extends ListHandler<ReferencedListDescriptor, ReferencedListValueDescriptor> {
19:
20: ReferencedListHandler(StorageConnector connector) {
21: super(connector);
22: }
23:
24: @Override
25: AbstractListIterator iterator(ReferencedListDescriptor descriptor) {
26: return new ReferencedListIterator(descriptor, connector);
27: }
28:
29: @Override
30: AbstractListIterator iterator(ReferencedListValueDescriptor descriptor) {
31: return iterator((ReferencedListDescriptor) descriptor);
32: }
33:
34: @Override
35: void appendNewNodes(ReferencedListValueDescriptor descriptor, int i, Resource lastNode) {
36:• assert lastNode != null;
37: final List<Statement> toAdd = new ArrayList<>((descriptor.getValues().size() - i) * 2);
38: final Property hasList = createProperty(descriptor.getListProperty().getIdentifier().toString());
39: final Property hasNext = createProperty(descriptor.getNextNode().getIdentifier().toString());
40: final Property hasContent = createProperty(descriptor.getNodeContent().getIdentifier().toString());
41:• final String context = descriptor.getContext() != null ? descriptor.getContext().toString() : null;
42:• for (; i < descriptor.getValues().size(); i++) {
43: lastNode =
44:• appendNode(lastNode, descriptor.getValues().get(i), i == 0 ? hasList : hasNext, hasContent, context,
45: toAdd);
46: }
47: connector.add(toAdd, context);
48: }
49:
50: private Resource appendNode(Resource previousNode, NamedResource value, Property link, Property hasContent,
51: String context, List<Statement> statements) {
52: final Resource node = generateNewListNode(value.getIdentifier(), context);
53: statements.add(createStatement(previousNode, link, node));
54: statements.add(createStatement(node, hasContent, createResource(value.getIdentifier().toString())));
55: return node;
56: }
57:
58: private Resource generateNewListNode(URI baseUri, String context) {
59: Resource node;
60: int index = 0;
61: Collection<Statement> statements;
62: do {
63: node = createResource(baseUri.toString() + "-SEQ_" + index++);
64: statements = connector.find(node, null, null, context);
65:• } while (!statements.isEmpty());
66: return node;
67: }
68: }