I am using java.util.concurrent.ConcurrentSkipListSet
. I define a class People
whose objects are held in a ConcurrentSkipListSet<People>
, a Comparator<People>
comparing Age
of People
, and that ConcurrentSkipListSet<People>
object is constructed via this Comparator<People>
.
If I have two People
objects having the same Age
, e.g. a.Age.equals(b.Age)
, what happens? Both a
and b
in the ConcurrentSkipListSet
? Or only one?
It's required that such a Comparator
must be consistent with equals, but in my case, a.Age.equals(b.Age)
definitely doesn't mean a.equals(b)
. I just want to sort People
objects by Age
.
Now my comparator is implemented as follows:
class ComparatorHSD implements Comparator<People> {
public int compare(People s0, People s1) {
int rv = 0;
if (s0.Age > s1.Age) {
rv = 1;
} else if (s0.Age < s1.Age) rv = -1;
return rv;
}
If I don't define rv = 0
, the program seems stuck somewhere and will not terminate. So I have define it? Why?