mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
修复CaseInsensitiveLinkedMap顺序错误问题
This commit is contained in:
parent
3aa9bdfcfa
commit
afe34a783d
@ -13,6 +13,7 @@
|
||||
* 【core 】 修复AnnotationUtil可能的空指针错误
|
||||
* 【core 】 修复BeanUtil.isBean判断Dict错误问题(issue#I9VTZG@Gitee)
|
||||
* 【core 】 修复VersionComparator传入空字符串报错问题(pr#3614@Github)
|
||||
* 【core 】 修复CaseInsensitiveLinkedMap顺序错误问题(issue#IA4K4F@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.28(2024-05-29)
|
||||
|
@ -61,7 +61,7 @@ public class CaseInsensitiveLinkedMap<K, V> extends CaseInsensitiveMap<K, V> {
|
||||
* @param loadFactor 加载因子
|
||||
*/
|
||||
public CaseInsensitiveLinkedMap(int initialCapacity, float loadFactor) {
|
||||
super(new LinkedHashMap<>(initialCapacity, loadFactor));
|
||||
super(MapBuilder.create(new LinkedHashMap<>(initialCapacity, loadFactor)));
|
||||
}
|
||||
// ------------------------------------------------------------------------- Constructor end
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ public class CaseInsensitiveMap<K, V> extends FuncKeyMap<K, V> {
|
||||
|
||||
/**
|
||||
* 构造<br>
|
||||
* 注意此构造将传入的Map作为被包装的Map,针对任何修改,传入的Map都会被同样修改。
|
||||
* 注意此构造将传入的Map所有值复制到当前map中,不修改传入map。
|
||||
*
|
||||
* @param m 被包装的自定义Map创建器
|
||||
*/
|
||||
|
@ -44,7 +44,7 @@ public class CaseInsensitiveTreeMap<K, V> extends CaseInsensitiveMap<K, V> {
|
||||
* @since 3.1.2
|
||||
*/
|
||||
public CaseInsensitiveTreeMap(SortedMap<? extends K, ? extends V> m) {
|
||||
super(new TreeMap<K, V>(m));
|
||||
super(MapBuilder.create(new TreeMap<K, V>(m)));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -53,7 +53,7 @@ public class CaseInsensitiveTreeMap<K, V> extends CaseInsensitiveMap<K, V> {
|
||||
* @param comparator 比较器,{@code null}表示使用默认比较器
|
||||
*/
|
||||
public CaseInsensitiveTreeMap(Comparator<? super K> comparator) {
|
||||
super(new TreeMap<>(comparator));
|
||||
super(MapBuilder.create(new TreeMap<>(comparator)));
|
||||
}
|
||||
// ------------------------------------------------------------------------- Constructor end
|
||||
}
|
||||
|
@ -1,25 +1,29 @@
|
||||
package cn.hutool.core.map;
|
||||
|
||||
import cn.hutool.core.lang.Pair;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CaseInsensitiveMapTest {
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveMapTest() {
|
||||
CaseInsensitiveMap<String, String> map = new CaseInsensitiveMap<>();
|
||||
map.put("aAA", "OK");
|
||||
Assert.assertEquals("OK", map.get("aaa"));
|
||||
Assert.assertEquals("OK", map.get("AAA"));
|
||||
assertEquals("OK", map.get("aaa"));
|
||||
assertEquals("OK", map.get("AAA"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void caseInsensitiveLinkedMapTest() {
|
||||
CaseInsensitiveLinkedMap<String, String> map = new CaseInsensitiveLinkedMap<>();
|
||||
map.put("aAA", "OK");
|
||||
Assert.assertEquals("OK", map.get("aaa"));
|
||||
Assert.assertEquals("OK", map.get("AAA"));
|
||||
assertEquals("OK", map.get("aaa"));
|
||||
assertEquals("OK", map.get("AAA"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -31,6 +35,42 @@ public class CaseInsensitiveMapTest {
|
||||
map.merge(b.getKey(), b.getValue(), (A, B) -> A);
|
||||
map.merge(a.getKey(), a.getValue(), (A, B) -> A);
|
||||
|
||||
Assert.assertEquals(1, map.size());
|
||||
assertEquals(1, map.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issueIA4K4FTest() {
|
||||
Map<String, Object> map = new CaseInsensitiveLinkedMap<>();
|
||||
map.put("b", 2);
|
||||
map.put("a", 1);
|
||||
|
||||
AtomicInteger index = new AtomicInteger();
|
||||
map.forEach((k, v) -> {
|
||||
if(0 == index.get()){
|
||||
assertEquals("b", k);
|
||||
} else if(1 == index.get()){
|
||||
assertEquals("a", k);
|
||||
}
|
||||
|
||||
index.getAndIncrement();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void issueIA4K4FTest2() {
|
||||
Map<String, Object> map = new CaseInsensitiveTreeMap<>();
|
||||
map.put("b", 2);
|
||||
map.put("a", 1);
|
||||
|
||||
AtomicInteger index = new AtomicInteger();
|
||||
map.forEach((k, v) -> {
|
||||
if(0 == index.get()){
|
||||
assertEquals("a", k);
|
||||
} else if(1 == index.get()){
|
||||
assertEquals("b", k);
|
||||
}
|
||||
|
||||
index.getAndIncrement();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user