From a8f9150333b7ddc232cd26c0af04f7fbd1da25b7 Mon Sep 17 00:00:00 2001 From: Marko Luukkainen Date: Wed, 16 Oct 2019 12:54:29 +0300 Subject: [PATCH] Improve matching logic for three way UpdateTree nodes. gitlab #14 Change-Id: I87e14b14d548113c084882dd7e82939495aff92a (cherry picked from commit 433fee716c37d0c82b6356100a13bf7b9f51e041) --- .../interop/update/model/UpdateNode3.java | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) 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; -- 2.45.1