Merge pull request #1871 from anaer/patch-13

fix typo, removeEqual对value为null情况未处理
This commit is contained in:
Golden Looly 2021-09-30 17:33:48 +08:00 committed by GitHub
commit 4cbcdce3e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -15,6 +15,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
/**
* 字典对象扩充了HashMap中的方法
@ -74,7 +75,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
* 根据给定的键值对数组创建Dict对象传入参数必须为key,value,key,value...
*
* <p>奇数参数必须为keykey最后会转换为String类型</p>
* <p>数参数必须为value可以为任意类型</p>
* <p>数参数必须为value可以为任意类型</p>
*
* <pre>
* Dict dict = Dict.of(
@ -291,7 +292,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
}
final Object value = this.get(entry.getKey());
if (null != value && value.equals(entry.getValue())) {
if (Objects.equals(value, entry.getValue())) {
this.remove(entry.getKey());
}
}

View File

@ -43,4 +43,19 @@ public class DictTest {
Assert.assertEquals("#00FF00", dict.get("GREEN"));
Assert.assertEquals("#0000FF", dict.get("BLUE"));
}
@Test
public void removeEqualTest(){
Dict dict = Dict.of(
"key1", null
);
Dict dict2 = Dict.of(
"key1", null
);
dict.removeEqual(dict2);
Assert.assertTrue(dict.isEmpty());
}
}