Package: LocalModel
LocalModel
name | instruction | branch | complexity | line | method | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
LocalModel() |
|
|
|
|
|
||||||||||||||||||||
addStatements(Collection) |
|
|
|
|
|
||||||||||||||||||||
contains(Resource, IRI, Value, IRI) |
|
|
|
|
|
||||||||||||||||||||
enhanceStatements(Collection, Resource, IRI, Value, IRI) |
|
|
|
|
|
||||||||||||||||||||
getAddedStatements() |
|
|
|
|
|
||||||||||||||||||||
getRemovedStatements() |
|
|
|
|
|
||||||||||||||||||||
removeStatements(Collection) |
|
|
|
|
|
Coverage
1: /**
2: * Copyright (C) 2016 Czech Technical University in Prague
3: * <p>
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: * <p>
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.sesame.connector;
16:
17: import org.eclipse.rdf4j.model.*;
18: import org.eclipse.rdf4j.model.impl.LinkedHashModel;
19:
20: import java.util.Collection;
21:
22: /**
23: * Caches local transactional changes to the Sesame repository model.
24: */
25: class LocalModel {
26:
27: private final Model addedStatements;
28: private final Model removedStatements;
29:
30: enum Contains {
31: TRUE, FALSE, UNKNOWN
32: }
33:
34: LocalModel() {
35: this.addedStatements = new LinkedHashModel();
36: this.removedStatements = new LinkedHashModel();
37: }
38:
39: void enhanceStatements(Collection<Statement> statements, Resource subject, IRI property,
40: Value object, IRI context) {
41: final Collection<Statement> added, removed;
42:• if (context != null) {
43: added = addedStatements.filter(subject, property, object, context);
44: removed = removedStatements.filter(subject, property, object, context);
45: } else {
46: added = addedStatements.filter(subject, property, object);
47: removed = removedStatements.filter(subject, property, object);
48: }
49: statements.addAll(added);
50: statements.removeAll(removed);
51: }
52:
53: Contains contains(Resource subject, IRI property, Value object, IRI context) {
54:• if (context != null) {
55:• if (addedStatements.contains(subject, property, object, context)) {
56: return Contains.TRUE;
57: }
58:• return removedStatements.contains(subject, property, object, context) ? Contains.FALSE : Contains.UNKNOWN;
59: } else {
60:• if (addedStatements.contains(subject, property, object)) {
61: return Contains.TRUE;
62: }
63:• return removedStatements.contains(subject, property, object) ? Contains.FALSE : Contains.UNKNOWN;
64: }
65: }
66:
67: void addStatements(Collection<Statement> statements) {
68: removedStatements.removeAll(statements);
69: addedStatements.addAll(statements);
70: }
71:
72: void removeStatements(Collection<Statement> statements) {
73: addedStatements.removeAll(statements);
74: removedStatements.addAll(statements);
75: }
76:
77: Collection<Statement> getAddedStatements() {
78: return addedStatements;
79: }
80:
81: Collection<Statement> getRemovedStatements() {
82: return removedStatements;
83: }
84: }