|
@@ -1,6 +1,5 @@
|
|
package com.pact;
|
|
package com.pact;
|
|
|
|
|
|
-import java.io.PrintStream;
|
|
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
|
|
|
|
@@ -14,11 +13,11 @@ public class Node
|
|
|
|
|
|
public Node(Node p, String s) {
|
|
public Node(Node p, String s) {
|
|
this.linkNode = null;
|
|
this.linkNode = null;
|
|
- this.linkNodes = new HashSet<Node>();
|
|
|
|
|
|
+ this.linkNodes = new HashSet();
|
|
this.venn = s;
|
|
this.venn = s;
|
|
this.parent = p;
|
|
this.parent = p;
|
|
|
|
|
|
- this.children = new HashSet<Node>();
|
|
|
|
|
|
+ this.children = new HashSet();
|
|
if (s.length() > 1)
|
|
if (s.length() > 1)
|
|
setChildren(s);
|
|
setChildren(s);
|
|
}
|
|
}
|
|
@@ -79,7 +78,7 @@ public class Node
|
|
|
|
|
|
public HashSet<Node> getSiblings() {
|
|
public HashSet<Node> getSiblings() {
|
|
if (this.parent != null) {
|
|
if (this.parent != null) {
|
|
- HashSet sibs = (HashSet)this.parent.children.clone();
|
|
|
|
|
|
+ HashSet<Node> sibs = (HashSet)this.parent.children.clone();
|
|
sibs.remove(this);
|
|
sibs.remove(this);
|
|
return sibs;
|
|
return sibs;
|
|
}
|
|
}
|
|
@@ -130,9 +129,22 @@ public class Node
|
|
|
|
|
|
public boolean equals(Object o)
|
|
public boolean equals(Object o)
|
|
{
|
|
{
|
|
- Node n = (Node)o;
|
|
|
|
- return equals(n);
|
|
|
|
- }
|
|
|
|
|
|
+ return equals((Node)o);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+// @Override
|
|
|
|
+// public int hashCode() {
|
|
|
|
+// if (children.isEmpty()) {
|
|
|
|
+// return venn.hashCode();
|
|
|
|
+// } else {
|
|
|
|
+// int h = 0;
|
|
|
|
+// for (Node child : children) {
|
|
|
|
+// h += child.hashCode();
|
|
|
|
+// }
|
|
|
|
+// return Integer.hashCode(h);
|
|
|
|
+// }
|
|
|
|
+//
|
|
|
|
+// }
|
|
|
|
|
|
private int getNumAreas() {
|
|
private int getNumAreas() {
|
|
int count = 0;
|
|
int count = 0;
|
|
@@ -187,15 +199,15 @@ public class Node
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean oneAreaShared(Node node1, Node node2)
|
|
|
|
|
|
+ private static boolean oneAreaShared(Node node1, Node node2)
|
|
{
|
|
{
|
|
- HashSet result = new HashSet();
|
|
|
|
|
|
+ HashSet<Nodes> result = new HashSet<>();
|
|
node2.deepSearch(node1, result);
|
|
node2.deepSearch(node1, result);
|
|
- HashSet largest = getLNodes(result);
|
|
|
|
|
|
+ HashSet<Nodes> largest = getLNodes(result);
|
|
if (largest.isEmpty()) {
|
|
if (largest.isEmpty()) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
- return (Nodes.setNodesSize(largest) == 1) && (largest.size() == 1);
|
|
|
|
|
|
+ return (Nodes.getNodesSize(largest) == 1) && (largest.size() == 1);
|
|
}
|
|
}
|
|
|
|
|
|
public HashSet<Node> combine(Node node) {
|
|
public HashSet<Node> combine(Node node) {
|
|
@@ -219,9 +231,9 @@ public class Node
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- HashSet largest = getLNodes(sResult);
|
|
|
|
|
|
+ HashSet<Nodes> largest = getLNodes(sResult);
|
|
|
|
|
|
- HashSet unsharedNodes = new HashSet();
|
|
|
|
|
|
+ HashSet<Node> unsharedNodes = new HashSet<>();
|
|
node2.collectUnshared(unsharedNodes);
|
|
node2.collectUnshared(unsharedNodes);
|
|
node1.collectUnshared(unsharedNodes);
|
|
node1.collectUnshared(unsharedNodes);
|
|
|
|
|
|
@@ -230,7 +242,7 @@ public class Node
|
|
Node toAdd = new Node(null, node1.getVenn());
|
|
Node toAdd = new Node(null, node1.getVenn());
|
|
result.add(toAdd);
|
|
result.add(toAdd);
|
|
return result;
|
|
return result;
|
|
- }if (node2.children.size() < node1.children.size()) {
|
|
|
|
|
|
+ } if (node2.children.size() < node1.children.size()) {
|
|
Node toAdd = new Node(null, node2.getVenn());
|
|
Node toAdd = new Node(null, node2.getVenn());
|
|
result.add(toAdd);
|
|
result.add(toAdd);
|
|
return result;
|
|
return result;
|
|
@@ -238,18 +250,17 @@ public class Node
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- if (largest.size() > 0)
|
|
|
|
- {
|
|
|
|
|
|
+ if (!largest.isEmpty()) {
|
|
Iterator itLargest = largest.iterator();
|
|
Iterator itLargest = largest.iterator();
|
|
|
|
|
|
Nodes flargest = (Nodes)itLargest.next();
|
|
Nodes flargest = (Nodes)itLargest.next();
|
|
|
|
|
|
- HashSet lg1sibs = flargest.node1.getSiblings();
|
|
|
|
- HashSet lg2sibs = flargest.node2.getSiblings();
|
|
|
|
|
|
+ HashSet<Node> lg1sibs = flargest.node1.getSiblings();
|
|
|
|
+ HashSet<Node> lg2sibs = flargest.node2.getSiblings();
|
|
|
|
|
|
- HashSet newSibs = new HashSet();
|
|
|
|
- HashSet otherSibs1 = new HashSet();
|
|
|
|
- HashSet otherSibs2 = new HashSet();
|
|
|
|
|
|
+ HashSet<Node> newSibs = new HashSet<>();
|
|
|
|
+ HashSet<Node> otherSibs1 = new HashSet<>();
|
|
|
|
+ HashSet<Node> otherSibs2 = new HashSet<>();
|
|
|
|
|
|
Iterator lg1It = lg1sibs.iterator();
|
|
Iterator lg1It = lg1sibs.iterator();
|
|
Iterator lg2It = lg2sibs.iterator();
|
|
Iterator lg2It = lg2sibs.iterator();
|
|
@@ -257,11 +268,10 @@ public class Node
|
|
sortLargestSibs(lg1It, flargest.node2, newSibs, otherSibs1);
|
|
sortLargestSibs(lg1It, flargest.node2, newSibs, otherSibs1);
|
|
sortLargestSibs(lg2It, flargest.node1, newSibs, otherSibs2);
|
|
sortLargestSibs(lg2It, flargest.node1, newSibs, otherSibs2);
|
|
|
|
|
|
- Iterator nsIt = newSibs.iterator();
|
|
|
|
|
|
|
|
if ((otherSibs1.isEmpty()) && (otherSibs2.isEmpty())) {
|
|
if ((otherSibs1.isEmpty()) && (otherSibs2.isEmpty())) {
|
|
- while (nsIt.hasNext()) {
|
|
|
|
- unsharedNodes.add((Node)nsIt.next());
|
|
|
|
|
|
+ for (Node newSib : newSibs) {
|
|
|
|
+ unsharedNodes.add(newSib);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -287,7 +297,7 @@ public class Node
|
|
HashSet polyresults = polyOne.combine(polyTwo);
|
|
HashSet polyresults = polyOne.combine(polyTwo);
|
|
Iterator prsIt = polyresults.iterator();
|
|
Iterator prsIt = polyresults.iterator();
|
|
while (prsIt.hasNext())
|
|
while (prsIt.hasNext())
|
|
- result.add((Node)prsIt.next());
|
|
|
|
|
|
+ result.add(prsIt.next());
|
|
}
|
|
}
|
|
else if (curr.node1.parent != null) {
|
|
else if (curr.node1.parent != null) {
|
|
String polyString1 = buildUp(curr.node1.parent, curr.node2.getVenn());
|
|
String polyString1 = buildUp(curr.node1.parent, curr.node2.getVenn());
|
|
@@ -315,14 +325,14 @@ public class Node
|
|
Iterator nRit = newResults.iterator();
|
|
Iterator nRit = newResults.iterator();
|
|
while (nRit.hasNext())
|
|
while (nRit.hasNext())
|
|
{
|
|
{
|
|
- result.add((Node)nRit.next());
|
|
|
|
|
|
+ result.add(nRit.next());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- if (Nodes.setNodesSize(largest) == 1)
|
|
|
|
|
|
+ if (Nodes.getNodesSize(largest) == 1)
|
|
{
|
|
{
|
|
HashSet unique = getUniqueNodes(sResult);
|
|
HashSet unique = getUniqueNodes(sResult);
|
|
Iterator uIt = unique.iterator();
|
|
Iterator uIt = unique.iterator();
|
|
@@ -342,7 +352,7 @@ public class Node
|
|
Iterator nRit = newResults.iterator();
|
|
Iterator nRit = newResults.iterator();
|
|
while (nRit.hasNext())
|
|
while (nRit.hasNext())
|
|
{
|
|
{
|
|
- result.add((Node)nRit.next());
|
|
|
|
|
|
+ result.add(nRit.next());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -354,14 +364,14 @@ public class Node
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- if (Nodes.setNodesSize(largest) > 1)
|
|
|
|
|
|
+ if (Nodes.getNodesSize(largest) > 1)
|
|
{
|
|
{
|
|
for (Object aLargest : largest) {
|
|
for (Object aLargest : largest) {
|
|
Nodes currL = (Nodes) aLargest;
|
|
Nodes currL = (Nodes) aLargest;
|
|
HashSet largeResult = subTrees(currL);
|
|
HashSet largeResult = subTrees(currL);
|
|
Iterator lrIt = largeResult.iterator();
|
|
Iterator lrIt = largeResult.iterator();
|
|
while (lrIt.hasNext()) {
|
|
while (lrIt.hasNext()) {
|
|
- result.add((Node) lrIt.next());
|
|
|
|
|
|
+ result.add(lrIt.next());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
@@ -372,7 +382,7 @@ public class Node
|
|
|
|
|
|
private void sortLargestSibs(Iterator<Node> lgsibs, Node lg, HashSet<Node> ns, HashSet<Node> os) {
|
|
private void sortLargestSibs(Iterator<Node> lgsibs, Node lg, HashSet<Node> ns, HashSet<Node> os) {
|
|
while (lgsibs.hasNext()) {
|
|
while (lgsibs.hasNext()) {
|
|
- Node curr = (Node)lgsibs.next();
|
|
|
|
|
|
+ Node curr = lgsibs.next();
|
|
Iterator linkIt = curr.linkNodes.iterator();
|
|
Iterator linkIt = curr.linkNodes.iterator();
|
|
boolean linkFlargest = false;
|
|
boolean linkFlargest = false;
|
|
if (linkIt.hasNext()) {
|
|
if (linkIt.hasNext()) {
|
|
@@ -445,21 +455,20 @@ public class Node
|
|
if (equals(node)) {
|
|
if (equals(node)) {
|
|
this.linkNodes.add(node);
|
|
this.linkNodes.add(node);
|
|
node.linkNodes.add(this);
|
|
node.linkNodes.add(this);
|
|
-
|
|
|
|
h.add(new Nodes(this, node));
|
|
h.add(new Nodes(this, node));
|
|
} else {
|
|
} else {
|
|
- Iterator it = this.children.iterator();
|
|
|
|
- while (it.hasNext())
|
|
|
|
- ((Node)(Node)it.next()).search(node, h);
|
|
|
|
|
|
+ for(Node child : children) {
|
|
|
|
+ child.search(node, h);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private HashSet<Nodes> searchBothNodes(Node node)
|
|
private HashSet<Nodes> searchBothNodes(Node node)
|
|
{
|
|
{
|
|
- HashSet<Nodes> sResult = new HashSet();
|
|
|
|
|
|
+ HashSet<Nodes> sResult = new HashSet<>();
|
|
search(node, sResult);
|
|
search(node, sResult);
|
|
|
|
|
|
- HashSet<Nodes> nsResult = new HashSet();
|
|
|
|
|
|
+ HashSet<Nodes> nsResult = new HashSet<>();
|
|
node.search(this, nsResult);
|
|
node.search(this, nsResult);
|
|
|
|
|
|
for (Nodes curr : nsResult) {
|
|
for (Nodes curr : nsResult) {
|
|
@@ -494,7 +503,7 @@ public class Node
|
|
}
|
|
}
|
|
|
|
|
|
private void resetSearch() {
|
|
private void resetSearch() {
|
|
- this.linkNodes = new HashSet<Node>();
|
|
|
|
|
|
+ this.linkNodes = new HashSet<>();
|
|
this.linkNode = null;
|
|
this.linkNode = null;
|
|
|
|
|
|
for (Node child : this.children) {
|
|
for (Node child : this.children) {
|
|
@@ -502,24 +511,21 @@ public class Node
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private HashSet<Nodes> getLNodes(HashSet<Nodes> h)
|
|
|
|
- {
|
|
|
|
- HashSet result = new HashSet();
|
|
|
|
- int size = 0;
|
|
|
|
|
|
+ /**
|
|
|
|
+ *
|
|
|
|
+ * @param h A HashSet
|
|
|
|
+ * @return The largest Nodes in h, based on the length of n1's Venn diagram
|
|
|
|
+ */
|
|
|
|
+ private static HashSet<Nodes> getLNodes(HashSet<Nodes> h) {
|
|
|
|
+ HashSet<Nodes> result = new HashSet<>();
|
|
|
|
+ int size = -1;
|
|
|
|
|
|
- Iterator it = h.iterator();
|
|
|
|
- if (it.hasNext()) {
|
|
|
|
- Nodes curr = (Nodes)it.next();
|
|
|
|
- size = curr.nodesSize();
|
|
|
|
- result.add(curr);
|
|
|
|
- }
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- Nodes curr = (Nodes)it.next();
|
|
|
|
- if (size < curr.nodesSize()) {
|
|
|
|
|
|
+ for(Nodes curr : h){
|
|
|
|
+ if (curr.nodesSize() > size) {
|
|
size = curr.nodesSize();
|
|
size = curr.nodesSize();
|
|
result.clear();
|
|
result.clear();
|
|
result.add(curr);
|
|
result.add(curr);
|
|
- } else if (size == curr.nodesSize()) {
|
|
|
|
|
|
+ } else if (curr.nodesSize() == size) {
|
|
result.add(curr);
|
|
result.add(curr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -528,72 +534,64 @@ public class Node
|
|
|
|
|
|
private Node combineAtRoot(Node node)
|
|
private Node combineAtRoot(Node node)
|
|
{
|
|
{
|
|
- HashSet uniqueNodes = new HashSet();
|
|
|
|
- Iterator thisIt = this.children.iterator();
|
|
|
|
- Iterator nodeIt = node.children.iterator();
|
|
|
|
|
|
+ HashSet<Node> uniqueNodes = new HashSet<>();
|
|
boolean reduced = false;
|
|
boolean reduced = false;
|
|
- while (thisIt.hasNext()) {
|
|
|
|
- Node curr = (Node)thisIt.next();
|
|
|
|
|
|
+ for(Node curr : this.children) {
|
|
if (!contains(curr, uniqueNodes))
|
|
if (!contains(curr, uniqueNodes))
|
|
uniqueNodes.add(curr);
|
|
uniqueNodes.add(curr);
|
|
else {
|
|
else {
|
|
reduced = true;
|
|
reduced = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- while (nodeIt.hasNext()) {
|
|
|
|
- Node curr = (Node)nodeIt.next();
|
|
|
|
|
|
+ for(Node curr : node.children) {
|
|
if (!contains(curr, uniqueNodes))
|
|
if (!contains(curr, uniqueNodes))
|
|
uniqueNodes.add(curr);
|
|
uniqueNodes.add(curr);
|
|
else {
|
|
else {
|
|
reduced = true;
|
|
reduced = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- Iterator unIt = uniqueNodes.iterator();
|
|
|
|
- String result = "(";
|
|
|
|
- while (unIt.hasNext()) {
|
|
|
|
- result = result + unIt.next();
|
|
|
|
- }
|
|
|
|
- result = result + ")";
|
|
|
|
-
|
|
|
|
if (!reduced) {
|
|
if (!reduced) {
|
|
return new Node(null, "(" + this.venn + node.getVenn() + ")");
|
|
return new Node(null, "(" + this.venn + node.getVenn() + ")");
|
|
|
|
+ } else {
|
|
|
|
+ String result_venn = "(";
|
|
|
|
+ for (Node unique : uniqueNodes) {
|
|
|
|
+ result_venn = result_venn + unique;
|
|
|
|
+ }
|
|
|
|
+ result_venn = result_venn + ")";
|
|
|
|
+ return new Node(null, result_venn);
|
|
}
|
|
}
|
|
- return new Node(null, result);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- private boolean unshared()
|
|
|
|
- {
|
|
|
|
- if (this.linkNodes.isEmpty())
|
|
|
|
- {
|
|
|
|
- Iterator it = this.children.iterator();
|
|
|
|
- if (!it.hasNext()) {
|
|
|
|
|
|
+ private boolean unshared() {
|
|
|
|
+ if (this.linkNodes.isEmpty()) {
|
|
|
|
+ if(this.children.isEmpty()) {
|
|
return true;
|
|
return true;
|
|
- }
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- if (!((Node)it.next()).unshared()) {
|
|
|
|
- return false;
|
|
|
|
|
|
+ } else {
|
|
|
|
+ for (Node node : this.children) {
|
|
|
|
+ if (!node.unshared()) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
return true;
|
|
|
|
+ } else {
|
|
|
|
+ return false;
|
|
}
|
|
}
|
|
- return false;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void collectUnshared(HashSet<Node> h) {
|
|
private void collectUnshared(HashSet<Node> h) {
|
|
if (unshared()) {
|
|
if (unshared()) {
|
|
h.add(this);
|
|
h.add(this);
|
|
}
|
|
}
|
|
- Iterator it = this.children.iterator();
|
|
|
|
- while (it.hasNext())
|
|
|
|
- ((Node)it.next()).collectUnshared(h);
|
|
|
|
|
|
+ for (Node child : children) {
|
|
|
|
+ child.collectUnshared(h);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
private HashSet<Nodes> getLinkedNodes(HashSet<Node> h)
|
|
private HashSet<Nodes> getLinkedNodes(HashSet<Node> h)
|
|
{
|
|
{
|
|
HashSet result = new HashSet();
|
|
HashSet result = new HashSet();
|
|
- Iterator hit = h.iterator();
|
|
|
|
- while (hit.hasNext()) {
|
|
|
|
- Node curr = (Node)hit.next();
|
|
|
|
|
|
+ for (Node curr : h) {
|
|
if (curr.hasLink() != null)
|
|
if (curr.hasLink() != null)
|
|
result.add(new Nodes(curr, curr.hasLink()));
|
|
result.add(new Nodes(curr, curr.hasLink()));
|
|
}
|
|
}
|
|
@@ -601,11 +599,8 @@ public class Node
|
|
}
|
|
}
|
|
|
|
|
|
private Node hasLink() {
|
|
private Node hasLink() {
|
|
- HashSet sibs = getSiblings();
|
|
|
|
- Iterator it = sibs.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- Node curr = (Node)it.next();
|
|
|
|
-
|
|
|
|
|
|
+ HashSet<Node> sibs = getSiblings();
|
|
|
|
+ for (Node curr : sibs) {
|
|
if (!curr.linkNodes.isEmpty()) {
|
|
if (!curr.linkNodes.isEmpty()) {
|
|
return curr;
|
|
return curr;
|
|
}
|
|
}
|
|
@@ -626,10 +621,9 @@ public class Node
|
|
}
|
|
}
|
|
String result = "(" + s;
|
|
String result = "(" + s;
|
|
if (n.parent != null) {
|
|
if (n.parent != null) {
|
|
- HashSet sibs = n.getSiblings();
|
|
|
|
- Iterator it = sibs.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- result = result + ((Node)it.next()).getVenn();
|
|
|
|
|
|
+ HashSet<Node> sibs = n.getSiblings();
|
|
|
|
+ for (Node sib : sibs) {
|
|
|
|
+ result = result + sib.getVenn();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
result = result + ")";
|
|
result = result + ")";
|
|
@@ -638,34 +632,26 @@ public class Node
|
|
|
|
|
|
private HashSet<HashSet<Nodes>> reviewPolys(HashSet<Nodes> h)
|
|
private HashSet<HashSet<Nodes>> reviewPolys(HashSet<Nodes> h)
|
|
{
|
|
{
|
|
- HashSet result = new HashSet();
|
|
|
|
- Iterator it = h.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- HashSet curresult = new HashSet();
|
|
|
|
- Nodes curr = (Nodes)it.next();
|
|
|
|
- Iterator currIt = h.iterator();
|
|
|
|
- while (currIt.hasNext()) {
|
|
|
|
- Nodes inCurr = (Nodes)currIt.next();
|
|
|
|
|
|
+ HashSet<HashSet<Nodes>> result = new HashSet<>();
|
|
|
|
+ for (Nodes curr : h) {
|
|
|
|
+ HashSet<Nodes> curresult = new HashSet<>();
|
|
|
|
+ for (Nodes inCurr : h) {
|
|
if (inCurr == curr) {
|
|
if (inCurr == curr) {
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
- HashSet linkedNodes = inCurr.node2.linkNodes;
|
|
|
|
- Iterator lnIt = linkedNodes.iterator();
|
|
|
|
|
|
+ HashSet<Node> linkedNodes = inCurr.node2.linkNodes;
|
|
boolean found = false;
|
|
boolean found = false;
|
|
- while (lnIt.hasNext()) {
|
|
|
|
- Node currln = (Node)lnIt.next();
|
|
|
|
|
|
+ for (Node currln : linkedNodes) {
|
|
if (currln == curr.node2) {
|
|
if (currln == curr.node2) {
|
|
found = true;
|
|
found = true;
|
|
inCurr.node2.linkNode = currln;
|
|
inCurr.node2.linkNode = currln;
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
if (found) {
|
|
if (found) {
|
|
curresult.add(inCurr);
|
|
curresult.add(inCurr);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
if (!curresult.isEmpty()) {
|
|
if (!curresult.isEmpty()) {
|
|
curresult.add(curr);
|
|
curresult.add(curr);
|
|
result.add(curresult);
|
|
result.add(curresult);
|
|
@@ -675,42 +661,39 @@ public class Node
|
|
}
|
|
}
|
|
|
|
|
|
private HashSet<Nodes> addPolys(HashSet<Nodes> h) {
|
|
private HashSet<Nodes> addPolys(HashSet<Nodes> h) {
|
|
- HashSet setresult = new HashSet();
|
|
|
|
- Iterator it = h.iterator();
|
|
|
|
- Nodes first = (Nodes)it.next();
|
|
|
|
- String result = first.node2.getVenn();
|
|
|
|
- result = result + first.node1.getVenn();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- result = result + ((Nodes)it.next()).node1.getVenn();
|
|
|
|
|
|
+ HashSet<Nodes> setResult = new HashSet<>();
|
|
|
|
+ Nodes first = null;
|
|
|
|
+ String result = "";
|
|
|
|
+ for (Nodes nodes : h) {
|
|
|
|
+ if (first == null) {
|
|
|
|
+ first = nodes;
|
|
|
|
+ result = first.node2.getVenn();
|
|
|
|
+ }
|
|
|
|
+ result += nodes.node1.getVenn();
|
|
}
|
|
}
|
|
- Iterator itr = h.iterator();
|
|
|
|
- while (itr.hasNext()) {
|
|
|
|
- Nodes toAdd = new Nodes(((Nodes)itr.next()).node2, new Node(null, "(" + result + ")"));
|
|
|
|
- setresult.add(toAdd);
|
|
|
|
|
|
+ for (Nodes nodes : h) {
|
|
|
|
+ Nodes toAdd = new Nodes((nodes).node2, new Node(null, "(" + result + ")"));
|
|
|
|
+ setResult.add(toAdd);
|
|
}
|
|
}
|
|
- return setresult;
|
|
|
|
|
|
+ return setResult;
|
|
}
|
|
}
|
|
|
|
|
|
private boolean isIn(Node node) {
|
|
private boolean isIn(Node node) {
|
|
if (this == node) {
|
|
if (this == node) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
- Iterator it = this.children.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- if (((Node)it.next()).isIn(node)) {
|
|
|
|
|
|
+ for (Node child : this.children) {
|
|
|
|
+ if (child.isIn(node)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
private HashSet<Node> getUniqueNodes(HashSet<Nodes> h)
|
|
private HashSet<Node> getUniqueNodes(HashSet<Nodes> h)
|
|
{
|
|
{
|
|
- HashSet result = new HashSet();
|
|
|
|
- Iterator it = h.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- Nodes curr = (Nodes)it.next();
|
|
|
|
|
|
+ HashSet<Node> result = new HashSet<>();
|
|
|
|
+ for (Nodes curr : h) {
|
|
if (!result.contains(curr.node1)) {
|
|
if (!result.contains(curr.node1)) {
|
|
result.add(curr.node1);
|
|
result.add(curr.node1);
|
|
}
|
|
}
|
|
@@ -722,10 +705,8 @@ public class Node
|
|
}
|
|
}
|
|
|
|
|
|
private HashSet<Node> getDuplicates(HashSet<Nodes> h) {
|
|
private HashSet<Node> getDuplicates(HashSet<Nodes> h) {
|
|
- HashSet result = new HashSet();
|
|
|
|
- Iterator it = h.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- Nodes curr = (Nodes)it.next();
|
|
|
|
|
|
+ HashSet<Node> result = new HashSet<>();
|
|
|
|
+ for (Nodes curr : h) {
|
|
if (curr.node1 == this)
|
|
if (curr.node1 == this)
|
|
result.add(curr.node2);
|
|
result.add(curr.node2);
|
|
else if (curr.node2 == this) {
|
|
else if (curr.node2 == this) {
|
|
@@ -737,16 +718,13 @@ public class Node
|
|
|
|
|
|
protected Node reduce()
|
|
protected Node reduce()
|
|
{
|
|
{
|
|
- HashSet c = this.children;
|
|
|
|
- HashSet uniqueC = new HashSet();
|
|
|
|
- HashSet dupC = new HashSet();
|
|
|
|
- Iterator it = c.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- Node curr = (Node)it.next();
|
|
|
|
- if (contains(curr, uniqueC))
|
|
|
|
- dupC.add(curr);
|
|
|
|
|
|
+ HashSet<Node> uniqueC = new HashSet<>();
|
|
|
|
+ HashSet<Node> dupC = new HashSet<>();
|
|
|
|
+ for (Node child : this.children) {
|
|
|
|
+ if (contains(child, uniqueC))
|
|
|
|
+ dupC.add(child);
|
|
else {
|
|
else {
|
|
- uniqueC.add(curr);
|
|
|
|
|
|
+ uniqueC.add(child);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if ((dupC.isEmpty()) || (this.venn.length() == 1)) {
|
|
if ((dupC.isEmpty()) || (this.venn.length() == 1)) {
|
|
@@ -769,9 +747,7 @@ public class Node
|
|
|
|
|
|
private boolean contains(Node n, HashSet<Node> h)
|
|
private boolean contains(Node n, HashSet<Node> h)
|
|
{
|
|
{
|
|
- Iterator it = h.iterator();
|
|
|
|
- while (it.hasNext()) {
|
|
|
|
- Node curr = (Node)it.next();
|
|
|
|
|
|
+ for (Node curr : h) {
|
|
if (curr.equals(n)) {
|
|
if (curr.equals(n)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|