Package: SimpleListHandler
SimpleListHandler
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
SimpleListHandler(StorageConnector) |
|
|
|
|
|
||||||||||||||||||||
appendNewNodes(SimpleListValueDescriptor, int, Resource) |
|
|
|
|
|
||||||||||||||||||||
appendNode(Resource, Property, NamedResource, List) |
|
|
|
|
|
||||||||||||||||||||
iterator(SimpleListDescriptor) |
|
|
|
|
|
||||||||||||||||||||
iterator(SimpleListValueDescriptor) |
|
|
|
|
|
Coverage
1: package cz.cvut.kbss.ontodriver.jena.list;
2:
3: import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor;
4: import cz.cvut.kbss.ontodriver.descriptor.SimpleListValueDescriptor;
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.ResourceFactory;
10: import org.apache.jena.rdf.model.Statement;
11:
12: import java.net.URI;
13: import java.util.ArrayList;
14: import java.util.List;
15:
16: import static org.apache.jena.rdf.model.ResourceFactory.createResource;
17:
18: class SimpleListHandler extends ListHandler<SimpleListDescriptor, SimpleListValueDescriptor> {
19:
20: SimpleListHandler(StorageConnector connector) {
21: super(connector);
22: }
23:
24: @Override
25: SimpleListIterator iterator(SimpleListDescriptor descriptor) {
26: return new SimpleListIterator(descriptor, connector);
27: }
28:
29: @Override
30: AbstractListIterator iterator(SimpleListValueDescriptor descriptor) {
31: return iterator((SimpleListDescriptor) descriptor);
32: }
33:
34: @Override
35: void appendNewNodes(SimpleListValueDescriptor descriptor, int index, Resource lastNode) {
36: final Property hasList = ResourceFactory
37: .createProperty(descriptor.getListProperty().getIdentifier().toString());
38: final Property hasNext = ResourceFactory.createProperty(descriptor.getNextNode().getIdentifier().toString());
39: final List<Statement> toAdd = new ArrayList<>(descriptor.getValues().size() - index);
40:• for (; index < descriptor.getValues().size(); index++) {
41:• lastNode = appendNode(lastNode, index == 0 ? hasList : hasNext, descriptor.getValues().get(index), toAdd);
42: }
43: final URI context = descriptor.getContext();
44:• connector.add(toAdd, context != null ? context.toString() : null);
45: }
46:
47: private Resource appendNode(Resource previous, Property property, NamedResource value, List<Statement> statements) {
48: final Resource node = createResource(value.getIdentifier().toString());
49: statements.add(ResourceFactory.createStatement(previous, property, node));
50: return node;
51: }
52: }