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

[2268 byte] By [DiegoCarzanigaa] at [2007-11-27 3:19:44]
# 1
Nobody can help me?Please....:-)
DiegoCarzanigaa at 2007-7-12 8:22:25 > top of Java-index,Java Essentials,Java Programming...
# 2
> ...> else {>if (this.equals(obj))>return 0;> else> return 1;>}>}Is that correct? Shouldn't you just return 0, and not use the Object.equals(Object)?
prometheuzza at 2007-7-12 8:22:25 > top of Java-index,Java Essentials,Java Programming...
# 3
I want to insert in my TreeSet Deadline with the same timestamp deadline, because this can happen. When timestamp is equal, get/remove method of TreeMap should navigate in its internal tree and search, between all Deadline with the same timestamp, that which satisfy equals check.
DiegoCarzanigaa at 2007-7-12 8:22:25 > top of Java-index,Java Essentials,Java Programming...