Reputation: 61
I have this class:
public abstract class Orderable<ID, T extends Comparable, V extends Orderable> implements Comparator<V>{
public abstract ID getId();
public abstract T getOrderParam();
public int compare(V o1, V o2) {
int compared = o1.getRankParam().compareTo(o2.getRankParam());
if (compared == 0) return o2.getId().toString().compareTo(o1.getId().toString());
return compared;
}
Now I'd like to create a ConcurrentSkipListMap passing as Comparator what I defined in Orderable Class. The goal is to keep ConcurrentSkipListMap ordered with comparator of V, where V is a generic class that extend Orderable.
private volatile ConcurrentSkipListMap<ID, V> concurrentSkipListMap;
private volatile AtomicInteger size;
public LeaderBoardImpl() {
concurrentSkipListMap = new ConcurrentSkipListMap<ID, V>(**** HERE I NEED TO PASS COMPARATOR****);
size = new AtomicInteger(0);
}
I'm not sure how to pass a Comparator of a generic Class. Thanks Albert
Upvotes: 0
Views: 87