Skip to content

Package: LocalModel

LocalModel

nameinstructionbranchcomplexitylinemethod
LocalModel()
M: 0 C: 18
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
addStatements(Collection)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
contains(Resource, IRI, Value, Set)
M: 0 C: 38
100%
M: 0 C: 6
100%
M: 0 C: 4
100%
M: 0 C: 5
100%
M: 0 C: 1
100%
enhanceStatements(Stream, Resource, IRI, Value, Collection)
M: 0 C: 39
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 8
100%
M: 0 C: 1
100%
getAddedStatements()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getRemovedStatements()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
getRemovedSubjectPredicateStatements()
M: 0 C: 3
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$enhanceStatements$0(Collection, Statement)
M: 0 C: 8
100%
M: 0 C: 2
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
lambda$enhanceStatements$1(Statement, SubjectPredicateContext)
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%
lambda$enhanceStatements$2(Statement)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
lambda$removePropertyValues$3(Statement, SubjectPredicateContext)
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%
lambda$removePropertyValues$4(Collection, Statement)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
removePropertyValues(Collection)
M: 0 C: 12
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%
removeStatements(Collection)
M: 0 C: 11
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 3
100%
M: 0 C: 1
100%

Coverage

1: /*
2: * JOPA
3: * Copyright (C) 2023 Czech Technical University in Prague
4: *
5: * This library is free software; you can redistribute it and/or
6: * modify it under the terms of the GNU Lesser General Public
7: * License as published by the Free Software Foundation; either
8: * version 3.0 of the License, or (at your option) any later version.
9: *
10: * This library is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this library.
17: */
18: package cz.cvut.kbss.ontodriver.rdf4j.connector;
19:
20: import org.eclipse.rdf4j.model.IRI;
21: import org.eclipse.rdf4j.model.Model;
22: import org.eclipse.rdf4j.model.Resource;
23: import org.eclipse.rdf4j.model.Statement;
24: import org.eclipse.rdf4j.model.Value;
25: import org.eclipse.rdf4j.model.impl.LinkedHashModel;
26:
27: import java.util.Collection;
28: import java.util.HashSet;
29: import java.util.List;
30: import java.util.Set;
31: import java.util.stream.Collectors;
32: import java.util.stream.Stream;
33:
34: /**
35: * Caches local transactional changes to the RDF4J repository model.
36: */
37: class LocalModel {
38:
39: private final Model addedStatements;
40: private final Model removedStatements;
41: private final Set<SubjectPredicateContext> removedSubjectPredicateStatements;
42:
43: enum Contains {
44: TRUE, FALSE, UNKNOWN
45: }
46:
47: LocalModel() {
48: this.addedStatements = new LinkedHashModel();
49: this.removedStatements = new LinkedHashModel();
50: this.removedSubjectPredicateStatements = new HashSet<>();
51: }
52:
53: List<Statement> enhanceStatements(Stream<Statement> statements, Resource subject, IRI property,
54: Value object, Collection<IRI> context) {
55: final IRI[] ctxArray = context.toArray(new IRI[0]);
56: final Collection<Statement> added = addedStatements.filter(subject, property, object, ctxArray);
57: final Collection<Statement> removed = removedStatements.filter(subject, property, object, ctxArray);
58:• final List<Statement> result = statements.filter(s -> !removed.contains(s))
59: .filter(s -> removedSubjectPredicateStatements.stream()
60: .noneMatch(spc -> spc.matches(s)))
61: .collect(Collectors.toList());
62: result.addAll(added);
63: return result;
64: }
65:
66: Contains contains(Resource subject, IRI property, Value object, Set<IRI> contexts) {
67: final IRI[] ctxArray = contexts.toArray(new IRI[0]);
68:• if (addedStatements.contains(subject, property, object, ctxArray)) {
69: return Contains.TRUE;
70: }
71:• return removedStatements.contains(subject, property, object, ctxArray) ||
72:• removedSubjectPredicateStatements.contains(new SubjectPredicateContext(subject, property, contexts)) ? Contains.FALSE : Contains.UNKNOWN;
73: }
74:
75: void addStatements(Collection<Statement> statements) {
76: removedStatements.removeAll(statements);
77: addedStatements.addAll(statements);
78: }
79:
80: void removeStatements(Collection<Statement> statements) {
81: addedStatements.removeAll(statements);
82: removedStatements.addAll(statements);
83: }
84:
85: void removePropertyValues(Collection<SubjectPredicateContext> toRemove) {
86: removedSubjectPredicateStatements.addAll(toRemove);
87: addedStatements.removeIf(s -> toRemove.stream().anyMatch(spc -> spc.matches(s)));
88: }
89:
90: Collection<Statement> getAddedStatements() {
91: return addedStatements;
92: }
93:
94: Collection<Statement> getRemovedStatements() {
95: return removedStatements;
96: }
97:
98: public Set<SubjectPredicateContext> getRemovedSubjectPredicateStatements() {
99: return removedSubjectPredicateStatements;
100: }
101: }