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: /**
2: * Copyright (C) 2022 Czech Technical University in Prague
3: *
4: * This program is free software: you can redistribute it and/or modify it under
5: * the terms of the GNU General Public License as published by the Free Software
6: * Foundation, either version 3 of the License, or (at your option) any
7: * later version.
8: *
9: * This program is distributed in the hope that it will be useful, but WITHOUT
10: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11: * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12: * details. You should have received a copy of the GNU General Public License
13: * along with this program. If not, see <http://www.gnu.org/licenses/>.
14: */
15: package cz.cvut.kbss.ontodriver.jena.list;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.SimpleListDescriptor;
18: import cz.cvut.kbss.ontodriver.descriptor.SimpleListValueDescriptor;
19: import cz.cvut.kbss.ontodriver.jena.connector.StorageConnector;
20: import cz.cvut.kbss.ontodriver.model.NamedResource;
21: import org.apache.jena.rdf.model.Property;
22: import org.apache.jena.rdf.model.Resource;
23: import org.apache.jena.rdf.model.ResourceFactory;
24: import org.apache.jena.rdf.model.Statement;
25:
26: import java.net.URI;
27: import java.util.ArrayList;
28: import java.util.List;
29:
30: import static org.apache.jena.rdf.model.ResourceFactory.createResource;
31:
32: class SimpleListHandler extends ListHandler<SimpleListDescriptor, SimpleListValueDescriptor> {
33:
34: SimpleListHandler(StorageConnector connector) {
35: super(connector);
36: }
37:
38: @Override
39: SimpleListIterator iterator(SimpleListDescriptor descriptor) {
40: return new SimpleListIterator(descriptor, connector);
41: }
42:
43: @Override
44: AbstractListIterator iterator(SimpleListValueDescriptor descriptor) {
45: return iterator((SimpleListDescriptor) descriptor);
46: }
47:
48: @Override
49: void appendNewNodes(SimpleListValueDescriptor descriptor, int index, Resource lastNode) {
50: final Property hasList = ResourceFactory
51: .createProperty(descriptor.getListProperty().getIdentifier().toString());
52: final Property hasNext = ResourceFactory.createProperty(descriptor.getNextNode().getIdentifier().toString());
53: final List<Statement> toAdd = new ArrayList<>(descriptor.getValues().size() - index);
54:• for (; index < descriptor.getValues().size(); index++) {
55:• lastNode = appendNode(lastNode, index == 0 ? hasList : hasNext, descriptor.getValues().get(index), toAdd);
56: }
57: final URI context = descriptor.getContext();
58:• connector.add(toAdd, context != null ? context.toString() : null);
59: }
60:
61: private static Resource appendNode(Resource previous, Property property, NamedResource value,
62: List<Statement> statements) {
63: final Resource node = createResource(value.getIdentifier().toString());
64: statements.add(ResourceFactory.createStatement(previous, property, node));
65: return node;
66: }
67: }