Breadth first search implementation in java