refactor finding leafs
larshp opened this issue · comments
much of the code in the following 2 methods are identical
public getDefinitions(): string {
let g = new Graph<Class>();
this.classes.forEach((c) => {
g.addNode(c.getName(), c);
c.getDependencies().forEach((d) => { g.addEdge(c.getName(), d); } );
});
let result = "";
while (g.countNodes() > 0) {
let leaf = g.popLeaf();
result = result + leaf.getDefinition() + "\n";
}
return result;
}
public getExceptions(): string {
let g = new Graph<Class>();
this.exceptions.forEach((c) => {
g.addNode(c.getName(), c);
c.getDependencies().forEach((d) => { g.addEdge(c.getName(), d); } );
});
let result = "";
while (g.countNodes() > 0) {
let leaf = g.popLeaf();
result = result + leaf.getDefinition() + "\n" + leaf.getImplementation() + "\n";
}
return result;
}
plus interfaces (in a bit)