reorganize netlist code, comment out unused functions

This commit is contained in:
Branislav Stojkovic
2019-03-14 22:36:43 +01:00
parent 41d2b73cca
commit 838adc9a51
6 changed files with 218 additions and 226 deletions
@@ -18,7 +18,6 @@
package org.diylc.netlist; package org.diylc.netlist;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -28,10 +27,27 @@ import java.util.Set;
import org.diylc.core.IDIYComponent; import org.diylc.core.IDIYComponent;
public class NetlistAnalyzer { public abstract class NetlistAnalyzer {
public NetlistAnalyzer() {} public NetlistAnalyzer() {}
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
Map<String, Summary> summaries = new HashMap<String, Summary>();
for (Netlist n : netlists) {
Summary s = summarize(n, preferredOutput);
if (summaries.containsKey(s.getSummary()))
summaries.get(s.getSummary()).append(n);
else
summaries.put(s.getSummary(), s);
}
List<Summary> res = new ArrayList<Summary>(summaries.values());
Collections.sort(res);
return res;
}
protected abstract Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException;
public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) { public Tree constructTreeBetween(Netlist netlist, Node nodeA, Node nodeB) {
Tree tree = new Tree(TreeConnectionType.Parallel); Tree tree = new Tree(TreeConnectionType.Parallel);
connectNodes(netlist, nodeA, nodeB, tree.getChildren(), new Tree(TreeConnectionType.Series), new HashSet<Node>()); connectNodes(netlist, nodeA, nodeB, tree.getChildren(), new Tree(TreeConnectionType.Series), new HashSet<Node>());
@@ -199,45 +215,45 @@ public class NetlistAnalyzer {
paths.addAll(unmerged); paths.addAll(unmerged);
} }
} }
//
protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath, // protected void findAllPaths(Netlist netlist, Node nodeA, Node nodeB, List<TreeLeaf> currentPath,
List<List<TreeLeaf>> allPaths, Set<Node> visited) { // List<List<TreeLeaf>> allPaths, Set<Node> visited) {
if (nodeA == nodeB) { // if (nodeA == nodeB) {
allPaths.add(currentPath); // allPaths.add(currentPath);
return; // return;
} // }
//
// System.out.println("Finding path between " + nodeA + " and " + nodeB); // // System.out.println("Finding path between " + nodeA + " and " + nodeB);
//
Group groupA = findGroup(netlist, nodeA); // Group groupA = findGroup(netlist, nodeA);
//
if (groupA == null) // if (groupA == null)
return; // return;
//
if (groupA.getNodes().contains(nodeB)) { // if (groupA.getNodes().contains(nodeB)) {
allPaths.add(currentPath); // allPaths.add(currentPath);
return; // return;
} // }
//
for (Node n : groupA.getNodes()) { // for (Node n : groupA.getNodes()) {
IDIYComponent<?> c = n.getComponent(); // IDIYComponent<?> c = n.getComponent();
for (int i = 0; i < c.getControlPointCount(); i++) { // for (int i = 0; i < c.getControlPointCount(); i++) {
if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) { // if (i != n.getPointIndex() && c.getInternalLinkName(i, n.getPointIndex()) != null) {
TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex()); // TreeLeaf l = new TreeLeaf(c, i, n.getPointIndex());
Node newNodeA = new Node(c, i); // Node newNodeA = new Node(c, i);
if (!visited.contains(newNodeA)) { // if (!visited.contains(newNodeA)) {
List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath); // List<TreeLeaf> newCurrentPath = new ArrayList<TreeLeaf>(currentPath);
if (!currentPath.contains(l)) // if (!currentPath.contains(l))
newCurrentPath.add(l); // newCurrentPath.add(l);
Set<Node> newVisited = new HashSet<Node>(visited); // Set<Node> newVisited = new HashSet<Node>(visited);
newVisited.add(nodeA); // newVisited.add(nodeA);
newVisited.add(newNodeA); // newVisited.add(newNodeA);
findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited); // findAllPaths(netlist, newNodeA, nodeB, newCurrentPath, allPaths, newVisited);
} // }
} // }
} // }
} // }
} // }
protected Group findGroup(Netlist netlist, Node node) { protected Group findGroup(Netlist netlist, Node node) {
for (Group g : netlist.getGroups()) for (Group g : netlist.getGroups())
@@ -246,62 +262,62 @@ public class NetlistAnalyzer {
return null; return null;
} }
protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) { // protected List<Group> trace(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Group> res = new ArrayList<Group>(); // List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) { // for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) { // for (Node n : g.getNodes()) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) // if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g); // res.add(g);
break; // break;
} // }
} // }
} // }
return res; // return res;
} // }
protected List<Node> find(Set<String> typeNames, String nodeName, Group group) { // protected List<Node> find(Set<String> typeNames, String nodeName, Group group) {
List<Node> res = new ArrayList<Node>(); // List<Node> res = new ArrayList<Node>();
//
// for (Node n : group.getNodes()) {
// if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
// res.add(n);
// }
// }
//
// return res;
// }
for (Node n : group.getNodes()) { // protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) {
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) // List<Group> res = new ArrayList<Group>();
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // for (Group g : netlist.getGroups()) {
res.add(n); // for (Node n : g.getNodes()) {
} // if (typeNames.contains(n.getComponent().getClass().getCanonicalName())
} // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
// res.add(g);
// break;
// }
// }
// }
// return res;
// }
return res; // protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist,
} // Collection<IDIYComponent<?>> belongTo) {
// List<Group> res = new ArrayList<Group>();
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist) { // for (Group g : netlist.getGroups()) {
List<Group> res = new ArrayList<Group>(); // for (Node n : g.getNodes()) {
for (Group g : netlist.getGroups()) { // if ((belongTo == null || belongTo.contains(n.getComponent()))
for (Node n : g.getNodes()) { // && (typeNames.contains(n.getComponent().getClass().getCanonicalName()))
if (typeNames.contains(n.getComponent().getClass().getCanonicalName()) // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // res.add(g);
res.add(g); // break;
break; // }
} // }
} // }
} // return res;
return res; // }
}
protected List<Group> findGroups(Set<String> typeNames, String nodeName, Netlist netlist,
Collection<IDIYComponent<?>> belongTo) {
List<Group> res = new ArrayList<Group>();
for (Group g : netlist.getGroups()) {
for (Node n : g.getNodes()) {
if ((belongTo == null || belongTo.contains(n.getComponent()))
&& (typeNames.contains(n.getComponent().getClass().getCanonicalName()))
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
res.add(g);
break;
}
}
}
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) { protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist) {
List<Node> res = new ArrayList<Node>(); List<Node> res = new ArrayList<Node>();
@@ -316,67 +332,67 @@ public class NetlistAnalyzer {
return res; return res;
} }
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) { // protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, List<Node> inGroupWith) {
List<Node> res = new ArrayList<Node>(); // List<Node> res = new ArrayList<Node>();
for (Group g : netlist.getGroups()) { // for (Group g : netlist.getGroups()) {
//
// boolean inGroup;
// if (inGroupWith == null) {
// inGroup = true;
// } else {
// inGroup = true;
// for (Node n1 : inGroupWith)
// if (!g.getNodes().contains(n1)) {
// inGroup = false;
// break;
// }
// }
//
// for (Node n : g.getNodes()) {
// if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName())
// && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
// res.add(n);
// }
// }
// }
// return res;
// }
boolean inGroup; // protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist,
if (inGroupWith == null) { // Collection<IDIYComponent<?>> belongTo) {
inGroup = true; // List<Node> res = new ArrayList<Node>();
} else { // for (Group g : netlist.getGroups()) {
inGroup = true; //
for (Node n1 : inGroupWith) // for (Node n : g.getNodes()) {
if (!g.getNodes().contains(n1)) { // if ((belongTo == null || belongTo.contains(n.getComponent()))
inGroup = false; // && typeNames.contains(n.getComponent().getClass().getCanonicalName())
break; // && (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) {
} // res.add(n);
} // }
// }
// }
// return res;
// }
for (Node n : g.getNodes()) { // protected boolean allMatch(Collection<Node> nodes, String name) {
if (inGroup && typeNames.contains(n.getComponent().getClass().getCanonicalName()) // for (Node n : nodes)
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // if (!n.getDisplayName().equalsIgnoreCase(name))
res.add(n); // return false;
} //
} // return true;
} // }
return res;
}
protected List<Node> find(Set<String> typeNames, String nodeName, Netlist netlist, // protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
Collection<IDIYComponent<?>> belongTo) { // Set<IDIYComponent<?>> extracted = extractComponents(nodes);
List<Node> res = new ArrayList<Node>(); // return extracted.containsAll(components);
for (Group g : netlist.getGroups()) { // }
//
for (Node n : g.getNodes()) { // protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
if ((belongTo == null || belongTo.contains(n.getComponent())) // Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
&& typeNames.contains(n.getComponent().getClass().getCanonicalName()) // for (Node n : nodes)
&& (nodeName == null || n.getDisplayName().equalsIgnoreCase(nodeName))) { // components.add(n.getComponent());
res.add(n); // return components;
} // }
}
}
return res;
}
protected boolean allMatch(Collection<Node> nodes, String name) {
for (Node n : nodes)
if (!n.getDisplayName().equalsIgnoreCase(name))
return false;
return true;
}
protected boolean allComponentsMatch(Collection<Node> nodes, Set<IDIYComponent<?>> components) {
Set<IDIYComponent<?>> extracted = extractComponents(nodes);
return extracted.containsAll(components);
}
protected Set<IDIYComponent<?>> extractComponents(Collection<Node> nodes) {
Set<IDIYComponent<?>> components = new HashSet<IDIYComponent<?>>();
for (Node n : nodes)
components.add(n.getComponent());
return components;
}
protected String extractName(IDIYComponent<?> c) { protected String extractName(IDIYComponent<?> c) {
return c.getName() + " " + c.getValueForDisplay(); return c.getName() + " " + c.getValueForDisplay();
@@ -397,53 +413,53 @@ public class NetlistAnalyzer {
return -1; return -1;
} }
protected List<String> extractNames(Collection<IDIYComponent<?>> components) { // protected List<String> extractNames(Collection<IDIYComponent<?>> components) {
List<String> names = new ArrayList<String>(); // List<String> names = new ArrayList<String>();
for (IDIYComponent<?> c : components) // for (IDIYComponent<?> c : components)
names.add(c.getName() + " " + c.getValueForDisplay()); // names.add(c.getName() + " " + c.getValueForDisplay());
Collections.sort(names); // Collections.sort(names);
return names; // return names;
} // }
//
protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) { // protected Netlist simplify(Netlist netlist, Set<Node> nodesToMerge, Collection<Node> nodesToPurge) {
Netlist res = new Netlist(); // Netlist res = new Netlist();
res.getSwitchSetup().addAll(netlist.getSwitchSetup()); // res.getSwitchSetup().addAll(netlist.getSwitchSetup());
//
Group merged = new Group(); // Group merged = new Group();
//
// merge // // merge
for (Group g : netlist.getGroups()) { // for (Group g : netlist.getGroups()) {
boolean needsMerging = false; // boolean needsMerging = false;
for (Node n : nodesToMerge) { // for (Node n : nodesToMerge) {
if (g.getNodes().contains(n)) { // if (g.getNodes().contains(n)) {
needsMerging = true; // needsMerging = true;
break; // break;
} // }
} // }
if (needsMerging) { // if (needsMerging) {
for (Node n : g.getNodes()) { // for (Node n : g.getNodes()) {
if (!nodesToMerge.contains(n)) // if (!nodesToMerge.contains(n))
merged.getNodes().add(n); // merged.getNodes().add(n);
} // }
} else { // } else {
res.getGroups().add(g.clone()); // res.getGroups().add(g.clone());
} // }
} // }
//
if (!merged.getNodes().isEmpty()) // if (!merged.getNodes().isEmpty())
res.getGroups().add(merged); // res.getGroups().add(merged);
//
// purge // // purge
for (Group g : res.getGroups()) { // for (Group g : res.getGroups()) {
g.getNodes().removeAll(nodesToPurge); // g.getNodes().removeAll(nodesToPurge);
} // }
//
System.out.println("Before:\n" + netlist); // System.out.println("Before:\n" + netlist);
System.out.println("After:\n" + res); // System.out.println("After:\n" + res);
//
return res; // return res;
} // }
//
protected boolean intersect(List<Group> groups, Node node) { protected boolean intersect(List<Group> groups, Node node) {
for (Group g : groups) for (Group g : groups)
if (g.getNodes().contains(node)) if (g.getNodes().contains(node))
Binary file not shown.
@@ -22,7 +22,6 @@
package org.diylc.netlist; package org.diylc.netlist;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@@ -85,26 +84,12 @@ public class GuitarDiagramAnalyzer extends NetlistAnalyzer implements INetlistAn
return new JLabel().getFont().getName(); return new JLabel().getFont().getName();
} }
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
Map<String, Summary> summaries = new HashMap<String, Summary>();
for (Netlist n : netlists) {
Summary s = summarize(n, preferredOutput);
if (summaries.containsKey(s.getSummary()))
summaries.get(s.getSummary()).append(n);
else
summaries.put(s.getSummary(), s);
}
List<Summary> res = new ArrayList<Summary>(summaries.values());
Collections.sort(res);
return res;
}
private int positiveCount; private int positiveCount;
private int negativeCount; private int negativeCount;
private int noiseCount; private int noiseCount;
private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException { protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
List<String> notes = new ArrayList<String>(); List<String> notes = new ArrayList<String>();
Tree tree = constructTree(netlist); Tree tree = constructTree(netlist);
@@ -49,16 +49,7 @@ public class SpiceAnalyzer extends NetlistAnalyzer implements INetlistAnalyzer {
return "Courier New"; return "Courier New";
} }
@Override protected Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
public List<Summary> summarize(List<Netlist> netlists, Node preferredOutput) throws TreeException {
List<Summary> summaries = new ArrayList<Summary>();
for (Netlist n : netlists)
summaries.add(summarize(n, preferredOutput));
return summaries;
}
private Summary summarize(Netlist netlist, Node preferredOutput) throws TreeException {
// grab all components that are in the netlist // grab all components that are in the netlist
List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(extractComponents(netlist)); List<IDIYComponent<?>> allComponents = new ArrayList<IDIYComponent<?>>(extractComponents(netlist));
Collections.sort(allComponents, new Comparator<IDIYComponent<?>>() { Collections.sort(allComponents, new Comparator<IDIYComponent<?>>() {
Binary file not shown.
Binary file not shown.