|
@@ -1,5 +1,6 @@
|
|
package com.pact;
|
|
package com.pact;
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -37,49 +38,55 @@ public class NodePair {
|
|
}
|
|
}
|
|
|
|
|
|
public HashSet<Node> combineSubTrees() {
|
|
public HashSet<Node> combineSubTrees() {
|
|
|
|
+ List<Node> res = _combineSubTrees();
|
|
|
|
+ return new HashSet(res);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public List<Node> _combineSubTrees() {
|
|
System.out.println("combineSubTrees==========================");
|
|
System.out.println("combineSubTrees==========================");
|
|
System.out.println("node1: " + node1.getVenn());
|
|
System.out.println("node1: " + node1.getVenn());
|
|
System.out.println("node2: " + node2.getVenn());
|
|
System.out.println("node2: " + node2.getVenn());
|
|
System.out.println("node1Full: " + node1.root().getVenn());
|
|
System.out.println("node1Full: " + node1.root().getVenn());
|
|
System.out.println("node2Full: " + node2.root().getVenn());
|
|
System.out.println("node2Full: " + node2.root().getVenn());
|
|
- HashSet<Node> commonSiblings = new HashSet<>();
|
|
|
|
|
|
+ List<Node> commonSiblings = new ArrayList<>();
|
|
|
|
|
|
- HashSet<Node> node1Siblings = this.node1.getSiblings();
|
|
|
|
|
|
+ List<Node> node1Siblings = new ArrayList<>(this.node1.getSiblings());
|
|
Iterator it1 = node1Siblings.iterator();
|
|
Iterator it1 = node1Siblings.iterator();
|
|
- HashSet<Node> node2Siblings = this.node2.getSiblings();
|
|
|
|
|
|
+ List<Node> node2Siblings = new ArrayList<>(this.node2.getSiblings());
|
|
Iterator it2 = node2Siblings.iterator();
|
|
Iterator it2 = node2Siblings.iterator();
|
|
|
|
|
|
- String siblingsVenn = "";
|
|
|
|
|
|
+ StringBuilder siblingsVenn = new StringBuilder();
|
|
|
|
|
|
if (!node1Siblings.isEmpty()) {
|
|
if (!node1Siblings.isEmpty()) {
|
|
- siblingsVenn = siblingsVenn + ((Node)it2.next()).getVenn();
|
|
|
|
|
|
+ siblingsVenn.append(((Node) it2.next()).getVenn());
|
|
} else {
|
|
} else {
|
|
if (it1.hasNext()) {
|
|
if (it1.hasNext()) {
|
|
- siblingsVenn = siblingsVenn + ((Node)it1.next()).getVenn();
|
|
|
|
|
|
+ siblingsVenn.append(((Node) it1.next()).getVenn());
|
|
if (it1.hasNext()) {
|
|
if (it1.hasNext()) {
|
|
- String temp = siblingsVenn;
|
|
|
|
- siblingsVenn = "(" + temp;
|
|
|
|
|
|
+ String temp = siblingsVenn.toString();
|
|
|
|
+ siblingsVenn = new StringBuilder("(" + temp);
|
|
while (it1.hasNext()) {
|
|
while (it1.hasNext()) {
|
|
- siblingsVenn = siblingsVenn + ((Node)it1.next()).getVenn();
|
|
|
|
|
|
+ siblingsVenn.append(((Node) it1.next()).getVenn());
|
|
}
|
|
}
|
|
- siblingsVenn = siblingsVenn + ")";
|
|
|
|
|
|
+ siblingsVenn.append(")");
|
|
}
|
|
}
|
|
- commonSiblings.add(new Node(null, siblingsVenn));
|
|
|
|
|
|
+ commonSiblings.add(new Node(null, siblingsVenn.toString()));
|
|
return commonSiblings;
|
|
return commonSiblings;
|
|
}
|
|
}
|
|
return commonSiblings;
|
|
return commonSiblings;
|
|
}
|
|
}
|
|
|
|
|
|
if (it2.hasNext()) {
|
|
if (it2.hasNext()) {
|
|
- String temp = siblingsVenn;
|
|
|
|
- siblingsVenn = "(" + temp;
|
|
|
|
|
|
+ String temp = siblingsVenn.toString();
|
|
|
|
+ siblingsVenn = new StringBuilder("(" + temp);
|
|
while (it2.hasNext()) {
|
|
while (it2.hasNext()) {
|
|
- siblingsVenn = siblingsVenn + ((Node)it2.next()).getVenn();
|
|
|
|
|
|
+ siblingsVenn.append(((Node) it2.next()).getVenn());
|
|
}
|
|
}
|
|
- siblingsVenn = siblingsVenn + ")";
|
|
|
|
|
|
+ siblingsVenn.append(")");
|
|
}
|
|
}
|
|
|
|
|
|
- Node nodesibs1 = new Node(null, siblingsVenn);
|
|
|
|
|
|
+ Node nodesibs1 = new Node(null, siblingsVenn.toString());
|
|
if (!it1.hasNext()) {
|
|
if (!it1.hasNext()) {
|
|
commonSiblings.add(nodesibs1);
|
|
commonSiblings.add(nodesibs1);
|
|
return commonSiblings;
|
|
return commonSiblings;
|
|
@@ -98,16 +105,11 @@ public class NodePair {
|
|
}
|
|
}
|
|
|
|
|
|
Node nodeSibs2 = new Node(null, siblings2);
|
|
Node nodeSibs2 = new Node(null, siblings2);
|
|
- HashSet<Node> result = Node.combine(nodesibs1, nodeSibs2);
|
|
|
|
- System.out.println("result: ");
|
|
|
|
- for(Node n : result){
|
|
|
|
- System.out.println("\t " + n.getVenn());
|
|
|
|
- }
|
|
|
|
- return result;
|
|
|
|
|
|
+ return new ArrayList(Node.combine(nodesibs1, nodeSibs2));
|
|
}
|
|
}
|
|
|
|
|
|
protected HashSet<NodePair> combineNew() {
|
|
protected HashSet<NodePair> combineNew() {
|
|
- HashSet<NodePair> setResult = new HashSet<>();
|
|
|
|
|
|
+ List<NodePair> setResult = new ArrayList<>();
|
|
Node resultNode1 = new Node(null, this.node2.root().getVenn());
|
|
Node resultNode1 = new Node(null, this.node2.root().getVenn());
|
|
String added = "(" + this.node2.getVenn() + this.node1.getVenn() + ")";
|
|
String added = "(" + this.node2.getVenn() + this.node1.getVenn() + ")";
|
|
|
|
|
|
@@ -116,7 +118,7 @@ public class NodePair {
|
|
Node resultNode2 = new Node(null, result);
|
|
Node resultNode2 = new Node(null, result);
|
|
setResult.add(new NodePair(resultNode1, resultNode2));
|
|
setResult.add(new NodePair(resultNode1, resultNode2));
|
|
}
|
|
}
|
|
- return setResult;
|
|
|
|
|
|
+ return new HashSet(setResult);
|
|
}
|
|
}
|
|
|
|
|
|
private String buildUp(Node n, String s) {
|
|
private String buildUp(Node n, String s) {
|