public boolean hasCycle() {

        for (Integer vertex : graph.getVertices()) {
            if (!visited.contains(vertex) && !dfs(vertex))
                return false;
        }
        return true;
    }
To find if the given graph has cycle , We need to maintain one additional set of exited vertices and do dfs.
In any step if iteration if a vertex is already in visited set and yet not exited from recusion stack, then
we can return true. We can optimize using one array with 3 different values.
src/algo/graph/CycleDetection.java