A Topological sort solution in Java