Skip to content

Package: SimpleListHandler

SimpleListHandler

nameinstructionbranchcomplexitylinemethod
SimpleListHandler(StorageConnector)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
appendNewNodes(SimpleListValueDescriptor, int, Resource)
M: 0 C: 56
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 9
100%
M: 0 C: 1
100%
appendNode(Resource, Property, NamedResource, List)
M: 0 C: 14
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
iterator(SimpleListDescriptor)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
iterator(SimpleListValueDescriptor)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
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.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 static Resource appendNode(Resource previous, Property property, NamedResource value,
48: List<Statement> statements) {
49: final Resource node = createResource(value.getIdentifier().toString());
50: statements.add(ResourceFactory.createStatement(previous, property, node));
51: return node;
52: }
53: }