TreeSet/TreeMap problem
Hi everyone!
I'm trying to implement a Scheduler which insert some Deadline in a TreeSet (sorted by expiration timestamp): another Thread "read" TreeSet in order to remove Deadline expired. For this purpose my Deadline class implements Comparable interface and the its method compareTo in this way:
publicint compareTo (Object obj){
Deadline d = (Deadline) obj;
if (this.deadline > d.deadline)
return 1;
elseif (d.deadline > this.deadline)
return -1;
else{
if (this.equals(obj))
return 0;
else
return 1;
}
}
My class Deadline doesn't extends any other class and doesn't re-implements method equals.
Belove part of my "killer" thread which "read" TreeSet:
.............
while (v.size() > 0){
dl = (Deadline) v.first();
if (dl.deadline <= last){
v.remove(dl);
}
ans = dl.deadline;
else{
ans = dl.deadline;
break;
}
.........
In some cases (probably when timestamp deadline of Deadline class is equal to that of another Deadlne) removal of Deadline is not performed: TreeSet methodfirst() give me a Deadline, but then I can't remove it from TreeSet. So TreeSet size is never decremented and I hava an infinite while cicle. Probably the problem is my implementation of method compareTo but I can't understand what is wrong!
Can somenone help me?
Thank you all in advance!
Diego

