class TopologyDag implements Serializable {

    List<Component> topOrder() {
        Map<Component, State> state = new HashMap<>();
        List<Component> res = new ArrayList<>();
        for(Component component: Sets.union(inputComponents, outputComponents)) {
            if (state.get(component) != State.VISITED) {
                res.addAll(dfs(component, state));
            }
        }
        Collections.reverse(res);
        return res;
    }

}