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 using Arrays.sort(pq.toArray()).
iterator()
Arrays.sort(pq.toArray())
There are probably other equivalent mechanisms.
1.4m articles
1.4m replys
5 comments
57.0k users