Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a CaseInsensitiveConcurrentMap?

How can I implement

class CaseInsensitiveConcurrentMap<V> implements ConcurrentMap<String , V>

which works just like ConcurrentHashMap<String , V> except that the keys are compared case-insensitively? The keys should not be converted to lowercase or uppercase.

Note that Collections.synchronizedMap(new TreeMap<String, new MyCaseInsensitiveComparator()) is no solution as it allows no concurrency and misses the additional methods.

Creating a String-like class with case-insensitive equals and hashCode is no option either, since the map has to be passed to methods expecting strings as keys.

like image 728
maaartinus Avatar asked Aug 05 '11 13:08

maaartinus


1 Answers

Have you tried

ConcurrentMap<String, Object> map = 
    new ConcurrentSkipListMap<String, Object>(
        String.CASE_INSENSITIVE_ORDER);
like image 144
Peter Lawrey Avatar answered Oct 11 '22 06:10

Peter Lawrey