40 |
*/ |
*/ |
41 |
private class Comp implements Comparator { |
private class Comp implements Comparator { |
42 |
public int compare(Object o1, Object o2) { |
public int compare(Object o1, Object o2) { |
43 |
Integer p1 = (Integer)jobPriority.get(o1); |
Float p1 = (Float)jobPriority.get(o1); |
44 |
Integer p2 = (Integer)jobPriority.get(o2); |
Float p2 = (Float)jobPriority.get(o2); |
45 |
int i1 = p1.intValue(); |
float f1 = p1.floatValue(); |
46 |
int i2 = p2.intValue(); |
float f2 = p2.floatValue(); |
47 |
if(i1 < i2) return -1; |
if(f1 < f2) return -1; |
48 |
if(i1 > i2) return 1; |
if(f1 > f2) return 1; |
49 |
i1 = o1.hashCode(); |
int i1 = o1.hashCode(); |
50 |
i2 = o2.hashCode(); |
int i2 = o2.hashCode(); |
51 |
if(i1 < i2) return -1; |
if(i1 < i2) return -1; |
52 |
if(i1 > i2) return 1; |
if(i1 > i2) return 1; |
53 |
return 0; |
return 0; |
54 |
} |
} |
55 |
} |
} |
56 |
|
|
57 |
/** Job object to Integer (the priority). |
/** Job object to Float (the priority). |
58 |
*/ |
*/ |
59 |
private Map jobPriority = new HashMap(); |
private Map jobPriority = new HashMap(); |
60 |
|
|
67 |
* If the job has already been added, set the priority |
* If the job has already been added, set the priority |
68 |
* to the lower value (more important) of the two. |
* to the lower value (more important) of the two. |
69 |
*/ |
*/ |
70 |
public void add(Object job, int priority) { |
public void add(Object job, float priority) { |
71 |
Integer prevprio = (Integer)jobPriority.get(job); |
Float prevprio = (Float)jobPriority.get(job); |
72 |
if(prevprio != null) { |
if(prevprio != null) { |
73 |
if(priority >= prevprio.intValue()) return; |
if(priority >= prevprio.intValue()) return; |
74 |
// Now, in order not to corrupt the TreeSet, |
// Now, in order not to corrupt the TreeSet, |
77 |
// has been changed. |
// has been changed. |
78 |
jobs.remove(job); |
jobs.remove(job); |
79 |
} |
} |
80 |
jobPriority.put(job, new Integer(priority)); |
jobPriority.put(job, new Float(priority)); |
81 |
jobs.add(job); |
jobs.add(job); |
82 |
} |
} |
83 |
|
|