Skip to content

Package: ListHandler

ListHandler

nameinstructionbranchcomplexitylinemethod
ListHandler(StorageConnector)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
loadList(ListDescriptor)
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
persistList(ListValueDescriptor)
M: 0 C: 19
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
referencedListHandler(StorageConnector)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
removeObsoleteNodes(AbstractListIterator)
M: 0 C: 10
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 4
100%
M: 0 C: 1
100%
simpleListHandler(StorageConnector)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
updateList(ListValueDescriptor)
M: 0 C: 49
100%
M: 0 C: 8
100%
M: 0 C: 5
100%
M: 0 C: 13
100%
M: 0 C: 1
100%

Coverage

1: package cz.cvut.kbss.ontodriver.jena.list;
2:
3: import cz.cvut.kbss.ontodriver.descriptor.ListDescriptor;
4: import cz.cvut.kbss.ontodriver.descriptor.ListValueDescriptor;
5: import cz.cvut.kbss.ontodriver.jena.connector.StorageConnector;
6: import cz.cvut.kbss.ontodriver.model.Axiom;
7: import cz.cvut.kbss.ontodriver.model.NamedResource;
8: import org.apache.jena.rdf.model.Resource;
9:
10: import java.util.ArrayList;
11: import java.util.List;
12:
13: import static org.apache.jena.rdf.model.ResourceFactory.createResource;
14:
15: public abstract class ListHandler<D extends ListDescriptor, V extends ListValueDescriptor> {
16:
17: final StorageConnector connector;
18:
19: ListHandler(StorageConnector connector) {
20: this.connector = connector;
21: }
22:
23: List<Axiom<NamedResource>> loadList(D descriptor) {
24: final List<Axiom<NamedResource>> result = new ArrayList<>();
25: final AbstractListIterator it = iterator(descriptor);
26:• while (it.hasNext()) {
27: result.add(it.nextAxiom());
28: }
29: return result;
30: }
31:
32: abstract AbstractListIterator iterator(D descriptor);
33:
34: abstract AbstractListIterator iterator(V descriptor);
35:
36: void persistList(V descriptor) {
37: final List<NamedResource> values = descriptor.getValues();
38:• if (values.isEmpty()) {
39: return;
40: }
41: Resource owner = createResource(descriptor.getListOwner().getIdentifier().toString());
42: appendNewNodes(descriptor, 0, owner);
43: }
44:
45: abstract void appendNewNodes(V descriptor, int index, Resource lastNode);
46:
47: void updateList(V descriptor) {
48: final AbstractListIterator it = iterator(descriptor);
49: int i = 0;
50:• while (it.hasNext() && i < descriptor.getValues().size()) {
51: final NamedResource update = descriptor.getValues().get(i);
52: final NamedResource existing = it.nextValue();
53:• if (!existing.equals(update)) {
54: it.replace(createResource(update.getIdentifier().toString()));
55: }
56: i++;
57: }
58: removeObsoleteNodes(it);
59:• if (i < descriptor.getValues().size()) {
60: appendNewNodes(descriptor, i, it.getCurrentNode());
61: }
62: }
63:
64: private static void removeObsoleteNodes(AbstractListIterator it) {
65:• while (it.hasNext()) {
66: it.nextValue();
67: it.removeWithoutReconnect();
68: }
69: }
70:
71: public static SimpleListHandler simpleListHandler(StorageConnector connector) {
72: return new SimpleListHandler(connector);
73: }
74:
75: public static ReferencedListHandler referencedListHandler(StorageConnector connector) {
76: return new ReferencedListHandler(connector);
77: }
78: }