for (Event e : pq)
doesn't iterate in the priority order.
while(!pq.isEmpty()){
Event e = pq.poll();
}
This works but empties the queue.
From the Javadocs
The Iterator provided in method
iterator()
is not guaranteed to traverse the elements of the PriorityQueue in any particular order. If you need ordered traversal, consider usingArrays.sort(pq.toArray())
.
There are probably other equivalent mechanisms.