-package org.simantics.interop.test;\r
-\r
-import java.util.List;\r
-\r
-import org.simantics.db.ReadGraph;\r
-import org.simantics.db.Resource;\r
-import org.simantics.db.Statement;\r
-import org.simantics.db.common.utils.NameUtils;\r
-import org.simantics.db.exception.ServiceException;\r
-import org.simantics.db.exception.ValidationException;\r
-import org.simantics.utils.datastructures.BijectionMap;\r
-import org.simantics.utils.datastructures.Pair;\r
-\r
-public class GraphChanges {\r
- \r
- private Resource r1;\r
- private Resource r2;\r
- private List<Statement> deletions;\r
- private List<Statement> additions;\r
- private List<Pair<Statement,Statement>> modifications;\r
- \r
- private BijectionMap<Resource, Resource> comparable;\r
- \r
- public GraphChanges(Resource r1, Resource r2, List<Statement> deletions, List<Statement> additions,\r
- List<Pair<Statement, Statement>> modifications, BijectionMap<Resource, Resource> comparable) {\r
- super();\r
- this.r1 = r1;\r
- this.r2 = r2;\r
- this.deletions = deletions;\r
- this.additions = additions;\r
- this.modifications = modifications;\r
- this.comparable = comparable;\r
- }\r
- \r
- public Resource getResource1() {\r
- return r1;\r
- }\r
- \r
- public Resource getResource2() {\r
- return r2;\r
- }\r
- \r
- public List<Statement> getAdditions() {\r
- return additions;\r
- }\r
- \r
- public List<Statement> getDeletions() {\r
- return deletions;\r
- }\r
- \r
- public List<Pair<Statement, Statement>> getModifications() {\r
- return modifications;\r
- }\r
- \r
- public BijectionMap<Resource, Resource> getComparable() {\r
- return comparable;\r
- }\r
- \r
- public String toString(ReadGraph graph) throws ValidationException, ServiceException {\r
- StringBuilder sb = new StringBuilder();\r
- sb.append("Del:\n");\r
- for (Statement stm : deletions) {\r
- sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+\r
- NameUtils.getSafeName(graph, stm.getPredicate()) + " " +\r
- NameUtils.getSafeName(graph, stm.getObject()) + " (" +\r
- stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");\r
- }\r
- sb.append("Add:\n");\r
- for (Statement stm : additions) {\r
- sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+\r
- NameUtils.getSafeName(graph, stm.getPredicate()) + " " +\r
- NameUtils.getSafeName(graph, stm.getObject()) + " (" +\r
- stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");\r
- }\r
- sb.append("Mod:\n");\r
- for (Pair<Statement, Statement> mod :modifications) {\r
- {\r
- Statement stm = mod.first;\r
- sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+\r
- NameUtils.getSafeName(graph, stm.getPredicate()) + " " +\r
- NameUtils.getSafeName(graph, stm.getObject()) + " (" +\r
- stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");\r
- }\r
- {\r
- Statement stm = mod.second;\r
- sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+\r
- NameUtils.getSafeName(graph, stm.getPredicate()) + " " +\r
- NameUtils.getSafeName(graph, stm.getObject()) + " (" +\r
- stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");\r
- }\r
- }\r
- return sb.toString();\r
- }\r
-\r
-}\r
+package org.simantics.interop.test;
+
+import java.util.List;
+import java.util.Map.Entry;
+
+import org.simantics.db.ReadGraph;
+import org.simantics.db.Resource;
+import org.simantics.db.Statement;
+import org.simantics.db.common.utils.NameUtils;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.utils.datastructures.BijectionMap;
+import org.simantics.utils.datastructures.Pair;
+
+public class GraphChanges {
+
+ private Resource r1;
+ private Resource r2;
+ private List<Statement> deletions;
+ private List<Statement> additions;
+ private List<Pair<Statement,Statement>> modifications;
+
+ private BijectionMap<Resource, Resource> comparable;
+
+ public GraphChanges(Resource r1, Resource r2, List<Statement> deletions, List<Statement> additions,
+ List<Pair<Statement, Statement>> modifications, BijectionMap<Resource, Resource> comparable) {
+ super();
+ this.r1 = r1;
+ this.r2 = r2;
+ this.deletions = deletions;
+ this.additions = additions;
+ this.modifications = modifications;
+ this.comparable = comparable;
+ }
+
+ public Resource getResource1() {
+ return r1;
+ }
+
+ public Resource getResource2() {
+ return r2;
+ }
+
+ public List<Statement> getAdditions() {
+ return additions;
+ }
+
+ public List<Statement> getDeletions() {
+ return deletions;
+ }
+
+ public List<Pair<Statement, Statement>> getModifications() {
+ return modifications;
+ }
+
+ public BijectionMap<Resource, Resource> getComparable() {
+ return comparable;
+ }
+
+ public String toString(ReadGraph graph) throws DatabaseException {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Del:\n");
+ for (Statement stm : deletions) {
+ sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+ NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+ NameUtils.getSafeName(graph, stm.getObject()) + " (" +
+ stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+ }
+ sb.append("Add:\n");
+ for (Statement stm : additions) {
+ sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+ NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+ NameUtils.getSafeName(graph, stm.getObject()) + " (" +
+ stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+ }
+ sb.append("Mod:\n");
+ for (Pair<Statement, Statement> mod :modifications) {
+ {
+ Statement stm = mod.first;
+ sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+ NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+ NameUtils.getSafeName(graph, stm.getObject()) + " (" +
+ stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+ }
+ {
+ Statement stm = mod.second;
+ sb.append(NameUtils.getSafeName(graph, stm.getSubject()) + " "+
+ NameUtils.getSafeName(graph, stm.getPredicate()) + " " +
+ NameUtils.getSafeName(graph, stm.getObject()) + " (" +
+ stm.getSubject() + " " +stm.getPredicate() + " " + stm.getObject() + ")\n");
+ }
+ }
+ return sb.toString();
+ }
+
+ public String comparableToString(ReadGraph graph) throws DatabaseException {
+ StringBuilder sb = new StringBuilder();
+ sb.append("Comparable:\n");
+ for (Entry<Resource, Resource> entry : comparable.getEntries()) {
+ sb.append(NameUtils.getSafeName(graph, entry.getKey()) + " "+
+ NameUtils.getSafeName(graph, entry.getValue()) + " (" +
+ entry.getKey() + " " +entry.getValue() + ")\n");
+
+ }
+ return sb.toString();
+ }
+
+}