return n3;
}
+ private static void getComparable(UpdateNode n, GraphChanges gc1, GraphChanges gc2, GraphChanges gc3, Set<Resource> 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 <T> void addNotNull(Set<T> set, T t) {
+ if (t != null)
+ set.add(t);
+ }
+
private static void populate(UpdateNode3 un, GraphChanges gc1, GraphChanges gc2, GraphChanges gc3) {
Set<UpdateNode> p1 = new HashSet<>();
Set<UpdateNode> p2 = new HashSet<>();
Set<UpdateNode> p3 = new HashSet<>();
-
+ Set<Resource> 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);
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);
}
}
- private static UpdateNode getMathcing(UpdateNode n , Collection<UpdateNode> coll, GraphChanges gc) {
+ private static UpdateNode getMatching(UpdateNode n , Collection<UpdateNode> coll, Set<Resource> set) {
if (n.getResource() == null) {
if (coll.size() != 1)
return null;
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;