private static <N> void doDfs( @NotNull N current, @NotNull Neighbors<N> neighbors, @NotNull Visited<N> visited, @NotNull NodeHandler<N, ?> handler) { if (!visited.checkAndMarkVisited(current)) { return; } handler.beforeChildren(current); for (N neighbor : neighbors.getNeighbors(current)) { doDfs(neighbor, neighbors, visited, handler); } handler.afterChildren(current); }