Browse Source

improve error message upon finding cycle

tags/2.0.1
Jonathan Cobb 5 years ago
parent
commit
7fd01de00a
1 changed files with 3 additions and 3 deletions
  1. +3
    -3
      src/main/java/org/cobbzilla/util/collection/Topology.java

+ 3
- 3
src/main/java/org/cobbzilla/util/collection/Topology.java View File

@@ -89,8 +89,8 @@ public class Topology<T> {
// remove edge e from the graph // remove edge e from the graph
final Edge<T> e = it.next(); final Edge<T> e = it.next();
final Node<T> m = e.to; final Node<T> m = e.to;
it.remove();//Remove edge from n
m.inEdges.remove(e);//Remove edge from m
it.remove(); // Remove edge from n
m.inEdges.remove(e); // Remove edge from m


// if m has no other incoming edges then insert m into S // if m has no other incoming edges then insert m into S
if (m.inEdges.isEmpty()) S.add(m); if (m.inEdges.isEmpty()) S.add(m);
@@ -99,7 +99,7 @@ public class Topology<T> {
// Check to see if all edges are removed // Check to see if all edges are removed
for (Node<T> n : nodes) { for (Node<T> n : nodes) {
if (!n.inEdges.isEmpty()) { if (!n.inEdges.isEmpty()) {
return die("Cycle present, topological sort not possible");
return die("Cycle present, topological sort not possible: "+n.thing.toString()+" <- ["+n.inEdges.stream().map(e->e.from.thing.toString()).collect(Collectors.joining(", "))+"]");
} }
} }
return L.stream().map(n -> n.thing).collect(Collectors.toList()); return L.stream().map(n -> n.thing).collect(Collectors.toList());


Loading…
Cancel
Save