Skip to content

Package: InferredReferencedListIterator

InferredReferencedListIterator

nameinstructionbranchcomplexitylinemethod
InferredReferencedListIterator(ReferencedListDescriptor, OntologySnapshot, AxiomAdapter)
M: 4 C: 20
83%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 5
83%
M: 0 C: 1
100%
doStep()
M: 0 C: 47
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 12
100%
M: 0 C: 1
100%
hasNext()
M: 0 C: 16
100%
M: 1 C: 5
83%
M: 1 C: 3
75%
M: 0 C: 3
100%
M: 0 C: 1
100%
nextValue()
M: 5 C: 24
83%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 6
86%
M: 0 C: 1
100%
removeWithoutReconnect()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
replaceNode(NamedResource)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

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.owlapi.list;
16:
17: import cz.cvut.kbss.ontodriver.descriptor.ReferencedListDescriptor;
18: import cz.cvut.kbss.ontodriver.model.NamedResource;
19: import cz.cvut.kbss.ontodriver.owlapi.AxiomAdapter;
20: import cz.cvut.kbss.ontodriver.owlapi.connector.OntologySnapshot;
21: import cz.cvut.kbss.ontodriver.owlapi.exception.ReasonerNotAvailableException;
22: import cz.cvut.kbss.ontodriver.owlapi.util.OwlapiUtils;
23: import org.semanticweb.owlapi.model.OWLIndividual;
24: import org.semanticweb.owlapi.model.OWLNamedIndividual;
25: import org.semanticweb.owlapi.model.OWLOntologyChange;
26: import org.semanticweb.owlapi.reasoner.OWLReasoner;
27:
28: import java.util.Collection;
29: import java.util.Collections;
30: import java.util.List;
31: import java.util.NoSuchElementException;
32: import java.util.stream.Collectors;
33:
34: class InferredReferencedListIterator extends ReferencedListIterator {
35:
36: private OWLNamedIndividual currentNode;
37: private final OWLReasoner reasoner;
38:
39: InferredReferencedListIterator(ReferencedListDescriptor descriptor, OntologySnapshot snapshot,
40: AxiomAdapter axiomAdapter) {
41: super(descriptor, snapshot, axiomAdapter);
42: this.reasoner = snapshot.getReasoner();
43:• if (reasoner == null) {
44: throw new ReasonerNotAvailableException();
45: }
46: this.currentNode = OwlapiUtils.getIndividual(descriptor.getListOwner(), snapshot.getDataFactory());
47: }
48:
49: @Override
50: public boolean hasNext() {
51:• if (nextItem == null) {
52: doStep();
53: }
54:• return nextItem != null && !nextItem.isEmpty();
55: }
56:
57: @Override
58: void doStep() {
59: final Collection<OWLNamedIndividual> nextNodes =
60: reasoner.getObjectPropertyValues(currentNode, currentNextNodeProperty).entities()
61: .collect(Collectors.toSet());
62:• if (nextNodes.isEmpty()) {
63: this.nextItem = Collections.emptyList();
64: return;
65: }
66: checkMaxSuccessors(currentNextNodeProperty, nextNodes);
67: this.currentNextNodeProperty = hasNextProperty;
68: this.currentNode = nextNodes.iterator().next();
69: this.nextItem = reasoner.getObjectPropertyValues(currentNode, hasContentProperty).entities()
70: .collect(Collectors.toSet());
71: }
72:
73: @Override
74: NamedResource nextValue() {
75:• if (!hasNext()) {
76: throw new NoSuchElementException("There are no more elements.");
77: }
78: checkMaxSuccessors(hasContentProperty, nextItem);
79: final OWLIndividual value = nextItem.iterator().next();
80: checkIsNamed(value);
81: doStep();
82: return NamedResource.create(value.asOWLNamedIndividual().getIRI().toURI());
83: }
84:
85: @Override
86: List<OWLOntologyChange> removeWithoutReconnect() {
87: throw new UnsupportedOperationException();
88: }
89:
90: @Override
91: List<OWLOntologyChange> replaceNode(NamedResource newValue) {
92: throw new UnsupportedOperationException();
93: }
94: }