]> gerrit.simantics Code Review - simantics/interop.git/commitdiff
Fix NPE in TypeComparator 22/2822/1
authorMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 28 Mar 2019 17:32:48 +0000 (19:32 +0200)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Thu, 28 Mar 2019 17:32:48 +0000 (19:32 +0200)
Additional change: debug print for found Resource matches

refs #9

Change-Id: I5c44a4a9696df03d4676ad30b272bc71c7029545

org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java
org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java

index facb75abce9ac752eea6f1229a5f656d685b64fd..b25eea87d49795573a2f26e2f33566d66fdd3f53 100644 (file)
-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();
+       }
+
+}
index 81d465609e024b8171503ce88345ff09db312772..6e1faa98067971c4b88de8c09114d07f0e0219c2 100644 (file)
@@ -26,10 +26,14 @@ public class TypeComparator extends ResourceComparator {
        
        @Override
        public int compare(ReadGraph g, Resource o1, Resource o2, boolean local) throws DatabaseException {
-               if (local)
-                       return new TypeComparator().compare(g, o1, o2);
-               else
-                       return compare(g, o1, o2);
+               if (o1.equals(o2)) {
+                       return 1;
+               }
+               return compare(g, o1, o2);
+//             if (local)
+//                     return new TypeComparator().compare(g, o1, o2);
+//             else
+//                     return compare(g, o1, o2);
        }
        
        @Override