I need to define a customized comparator to ConcurrentSkipListMap, I use this code to sort based on ‘LogicalClock’ but the result is not as I expected. I create the key like this: “ClientId”+”:”+”LogicalClock”
class Qentry{
int AckCount;
int ClientID;
long LogicalClock;
}
Comparator<String> LogicalClockComparator = new Comparator<String>() {
@Override public int compare(String k1, String k2) {
if (k1.compareTo(k2)==0)
return 0;
return (int)( Long.valueOf(k1.substring(k1.indexOf(":")+1)) -Long.valueOf(k2.substring(k1.indexOf(":")+1) ));
}
ConcurrentSkipListMap<String,Qentry> q;
q =new ConcurrentSkipListMap<String,Qentry>(LogicalClockComparator);
Looks like a typo (or copy/paste error) to me, maybe you want to use (look at the end of the line)
instead of what you had: