Topological Sorting implementation for graphs in java