class GraphCycleDetector {

    public Set<String> checkCycles() {

        // Remove root units recursively
        removeNodesWithoutParents();

        // Remove leaf units recursively
        removeNodesWithoutChildren();

        // Compute cycles
        return getCycles();
    }

}