Same priority items in a priority queue

Hello all,

I am writing a project that uses the PriorityQueue class to sort patients according to their emergency level.

The more urgent is a patient's condition, the higher the priority (Priority 1 = Very Urgent. Priority 10 = Not urgent).

However, there are many patients with the same priority and I would like to process them according to a first-in first-out scheme.

The PriorityQueue class doesn't seem to follow that scheme naturally.

Does anyone have an idea how to solve this problem?

Thanks in advance,

Nader

[572 byte] By [NaderChehaba] at [2007-10-3 8:09:29]
# 1
Looks like you'll have to subclass PriorityQueue and implement your own poll() method. As you pointed out, the default PriorityQueue acts as follows:If multiple elements are tied for least value, the head is one of those elements -- ties are broken arbitrarilyBrian
brian@cubik.caa at 2007-7-15 3:13:45 > top of Java-index,Core,Core APIs...
# 2
Just overriding poll() won't do it; the ordering is done all over the place.Define your own Comparator for the PriorityQueue and have it break ties on emergency level by looking at arrival time, which you will have to put into your objects.
ejpa at 2007-7-15 3:13:45 > top of Java-index,Core,Core APIs...
# 3
Yeah I will try that. Thanks!
NaderChehaba at 2007-7-15 3:13:45 > top of Java-index,Core,Core APIs...