From: Marko Luukkainen Date: Wed, 16 Oct 2019 09:54:29 +0000 (+0300) Subject: Improve matching logic for three way UpdateTree nodes. X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F40%2F3340%2F1;p=simantics%2Finterop.git Improve matching logic for three way UpdateTree nodes. gitlab #14 Change-Id: I87e14b14d548113c084882dd7e82939495aff92a (cherry picked from commit 433fee716c37d0c82b6356100a13bf7b9f51e041) --- diff --git a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java index 9df0830..a147647 100644 --- a/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java +++ b/org.simantics.interop.update/src/org/simantics/interop/update/model/UpdateNode3.java @@ -71,22 +71,40 @@ public class UpdateNode3 { return n3; } + private static void getComparable(UpdateNode n, GraphChanges gc1, GraphChanges gc2, GraphChanges gc3, Set nodeR) { + nodeR.clear(); + Resource r = n.getResource(); + nodeR.add(r); + addNotNull(nodeR,gc1.getComparable().getLeft(r)); + addNotNull(nodeR,gc1.getComparable().getRight(r)); + addNotNull(nodeR,gc2.getComparable().getLeft(r)); + addNotNull(nodeR,gc2.getComparable().getRight(r)); + addNotNull(nodeR,gc3.getComparable().getLeft(r)); + addNotNull(nodeR,gc3.getComparable().getRight(r)); + + } + + public static void addNotNull(Set set, T t) { + if (t != null) + set.add(t); + } + private static void populate(UpdateNode3 un, GraphChanges gc1, GraphChanges gc2, GraphChanges gc3) { Set p1 = new HashSet<>(); Set p2 = new HashSet<>(); Set p3 = new HashSet<>(); - + Set nodeR = new HashSet<>(); if (un.getUn1() != null) { for (UpdateNode n1 : un.getUn1().getChildren()) { + getComparable(n1, gc1, gc2, gc3, nodeR); p1.add(n1); - UpdateNode n2 = null; - if (un.getUn2() != null) - n2 = getMathcing(n1, un.getUn2().getChildren(), gc1); + UpdateNode n2 = null; + if (un.getUn2() != null) { + n2 = getMatching(n1, un.getUn2().getChildren(), nodeR); + } UpdateNode n3 = null; if (un.getUn3() != null) { - n3 = getMathcing(n1, un.getUn3().getChildren(), gc2); - if (n3 == null && n2 != null) - n3 = getMathcing(n2, un.getUn3().getChildren(), gc3); + n3 = getMatching(n1, un.getUn3().getChildren(), nodeR); } UpdateNode3 cn = new UpdateNode3(n1, n2, n3); un.children.add(cn); @@ -103,10 +121,10 @@ public class UpdateNode3 { if (p2.contains(n2)) continue; p2.add(n2); - + getComparable(n2, gc1, gc2, gc3, nodeR); UpdateNode n3 = null; if (un.getUn3() != null) { - n3 = getMathcing(n2, un.getUn3().getChildren(), gc3); + n3 = getMatching(n2, un.getUn3().getChildren(), nodeR); } UpdateNode3 cn = new UpdateNode3(null, n2, n3); un.children.add(cn); @@ -128,7 +146,7 @@ public class UpdateNode3 { } } - private static UpdateNode getMathcing(UpdateNode n , Collection coll, GraphChanges gc) { + private static UpdateNode getMatching(UpdateNode n , Collection coll, Set set) { if (n.getResource() == null) { if (coll.size() != 1) return null; @@ -137,13 +155,9 @@ public class UpdateNode3 { return null; return n2; } - Resource o = gc.getComparable().getLeft(n.getResource()); - if (o == null) - o = gc.getComparable().getRight(n.getResource()); - if (o == null) - o = n.getResource(); + for (UpdateNode c : coll) { - if (o.equals(c.getResource())) + if (set.contains(c.getResource())) return c; } return null;