修复BiMap中未重写computeIfAbsent和putIfAbsent导致双向查找出问题

This commit is contained in:
Looly
2022-11-26 12:07:20 +08:00
parent 4e06f02610
commit d6134f707d
3 changed files with 73 additions and 3 deletions

View File

@@ -9,7 +9,7 @@ public class BiMapTest {
@Test
public void getTest(){
BiMap<String, Integer> biMap = new BiMap<>(new HashMap<>());
final BiMap<String, Integer> biMap = new BiMap<>(new HashMap<>());
biMap.put("aaa", 111);
biMap.put("bbb", 222);
@@ -19,4 +19,26 @@ public class BiMapTest {
Assert.assertEquals("aaa", biMap.getKey(111));
Assert.assertEquals("bbb", biMap.getKey(222));
}
@Test
public void computeIfAbsentTest(){
final BiMap<String, Integer> biMap = new BiMap<>(new HashMap<>());
biMap.put("aaa", 111);
biMap.put("bbb", 222);
biMap.computeIfAbsent("ccc", s -> 333);
Assert.assertEquals(new Integer(333), biMap.get("ccc"));
Assert.assertEquals("ccc", biMap.getKey(333));
}
@Test
public void putIfAbsentTest(){
final BiMap<String, Integer> biMap = new BiMap<>(new HashMap<>());
biMap.put("aaa", 111);
biMap.put("bbb", 222);
biMap.putIfAbsent("ccc", 333);
Assert.assertEquals(new Integer(333), biMap.get("ccc"));
Assert.assertEquals("ccc", biMap.getKey(333));
}
}