boolean safeToClean(Graph g, int v, Map<Edge,Edge> replacements) { final int d = g.degree(v); for (int j = 0; j < d; ++j) { final Edge e = g.edgeAt(v, j); if (e.bond().order() == 2) { int w = e.other(v); final int d2 = g.degree(w); for (int j2 = 0; j2 < d2; ++j2) { final Edge f = g.edgeAt(w, j2); if (isDirectional(f, replacements)) return false; } } } return true; }
for (int j = 0; j < d; ++j) { final Edge f = g.edgeAt(u, j); if (isDirectional(f, replacements) && safeToClean(g, f.other(u), replacements)) { replacements.put(f, new Edge(u, f.other(u), Bond.IMPLICIT)); for (int j = 0; j < d2; ++j) { final Edge f = g.edgeAt(v, j); if (isDirectional(f, replacements) && safeToClean(g, f.other(v), replacements)) replacements.put(f, new Edge(v, f.other(v), Bond.IMPLICIT));