fix ugly initialisation in while loop over queue
It would be better to do 

for (Integer element; (element = queue.poll) != null;){

}


Because you don't want element to be in the scope after the loop has ended