8 |
* N.B. the current implementation is not the most efficient |
* N.B. the current implementation is not the most efficient |
9 |
* possible one, |
* possible one, |
10 |
* by far. |
* by far. |
11 |
|
* <p> |
12 |
|
* This class is not synchronized! |
13 |
*/ |
*/ |
14 |
|
|
15 |
public class PriorityQueue { |
public class PriorityQueue { |
46 |
* If the job has already been added, set the priority |
* If the job has already been added, set the priority |
47 |
* to the lower value (more important) of the two. |
* to the lower value (more important) of the two. |
48 |
*/ |
*/ |
49 |
public synchronized void add(Object job, int priority) { |
public void add(Object job, int priority) { |
50 |
Integer prevprio = (Integer)jobPriority.get(job); |
Integer prevprio = (Integer)jobPriority.get(job); |
51 |
if(prevprio != null) { |
if(prevprio != null) { |
52 |
if(priority >= prevprio.intValue()) return; |
if(priority >= prevprio.intValue()) return; |
63 |
/** Get the most important (with lowest numeric priority) job and remove |
/** Get the most important (with lowest numeric priority) job and remove |
64 |
* it from this queue. |
* it from this queue. |
65 |
*/ |
*/ |
66 |
public synchronized Object getAndRemoveLowest() { |
public Object getAndRemoveLowest() { |
67 |
if(jobs.isEmpty()) return null; |
if(jobs.isEmpty()) return null; |
68 |
Object j = jobs.first(); |
Object j = jobs.first(); |
69 |
jobs.remove(j); |
jobs.remove(j); |