如何制作一个CaseInsensitiveConcurrentMap? [英] How to make a CaseInsensitiveConcurrentMap?

查看:52
本文介绍了如何制作一个CaseInsensitiveConcurrentMap?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何实现

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

除了键是不区分大小写的比较之外,它与 ConcurrentHashMap< 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.

请注意, Collections.synchronizedMap(new TreeMap< String,new MyCaseInsensitiveComparator())不是解决方案,因为它不允许并发并且错过了其他方法.

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

创建一个不区分大小写的 equals hashCode 的类似String的类也不可行,因为必须将映射传递给以字符串为键的方法./p>

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.

推荐答案

您尝试过

ConcurrentMap<String, Object> map = 
    new ConcurrentSkipListMap<String, Object>(
        String.CASE_INSENSITIVE_ORDER);

这篇关于如何制作一个CaseInsensitiveConcurrentMap?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆