From aa4da931fd1a692a877f90e4bc676640b09ba5c1 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Thu, 28 Mar 2019 19:32:48 +0200 Subject: [PATCH] Fix NPE in TypeComparator Additional change: debug print for found Resource matches refs #9 Change-Id: I5c44a4a9696df03d4676ad30b272bc71c7029545 --- .../simantics/interop/test/GraphChanges.java | 202 ++++++++++-------- .../interop/test/TypeComparator.java | 12 +- 2 files changed, 115 insertions(+), 99 deletions(-) diff --git a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java index facb75a..b25eea8 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java +++ b/org.simantics.interop/src/org/simantics/interop/test/GraphChanges.java @@ -1,95 +1,107 @@ -package org.simantics.interop.test; - -import java.util.List; - -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.ServiceException; -import org.simantics.db.exception.ValidationException; -import org.simantics.utils.datastructures.BijectionMap; -import org.simantics.utils.datastructures.Pair; - -public class GraphChanges { - - private Resource r1; - private Resource r2; - private List deletions; - private List additions; - private List> modifications; - - private BijectionMap comparable; - - public GraphChanges(Resource r1, Resource r2, List deletions, List additions, - List> modifications, BijectionMap 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 getAdditions() { - return additions; - } - - public List getDeletions() { - return deletions; - } - - public List> getModifications() { - return modifications; - } - - public BijectionMap getComparable() { - return comparable; - } - - public String toString(ReadGraph graph) throws ValidationException, ServiceException { - 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 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(); - } - -} +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 deletions; + private List additions; + private List> modifications; + + private BijectionMap comparable; + + public GraphChanges(Resource r1, Resource r2, List deletions, List additions, + List> modifications, BijectionMap 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 getAdditions() { + return additions; + } + + public List getDeletions() { + return deletions; + } + + public List> getModifications() { + return modifications; + } + + public BijectionMap 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 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 entry : comparable.getEntries()) { + sb.append(NameUtils.getSafeName(graph, entry.getKey()) + " "+ + NameUtils.getSafeName(graph, entry.getValue()) + " (" + + entry.getKey() + " " +entry.getValue() + ")\n"); + + } + return sb.toString(); + } + +} diff --git a/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java b/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java index 81d4656..6e1faa9 100644 --- a/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java +++ b/org.simantics.interop/src/org/simantics/interop/test/TypeComparator.java @@ -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 -- 2.47.1