From 836080240e42209b12ebbf0524bd93d5651fc962 Mon Sep 17 00:00:00 2001 From: Looly Date: Tue, 9 Dec 2025 17:39:47 +0800 Subject: [PATCH] add test --- .../cn/hutool/core/collection/CollUtil.java | 8 +++---- .../hutool/core/collection/CollUtilTest.java | 21 ++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java index 05e0d78d96..270db8ac75 100755 --- a/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/collection/CollUtil.java @@ -575,7 +575,7 @@ public class CollUtil { } } - if (false == foundCurrentElement) { + if (!foundCurrentElement) { return false; } } @@ -1805,7 +1805,7 @@ public class CollUtil { * @return 是否为空 */ public static boolean isEmpty(Enumeration enumeration) { - return null == enumeration || false == enumeration.hasMoreElements(); + return null == enumeration || !enumeration.hasMoreElements(); } /** @@ -2336,7 +2336,7 @@ public class CollUtil { */ public static List addAllIfNotContains(List list, List otherList) { for (T t : otherList) { - if (false == list.contains(t)) { + if (!list.contains(t)) { list.add(t); } } @@ -2841,7 +2841,7 @@ public class CollUtil { @Override public int hash32(T t) { - if (null == t || false == BeanUtil.isBean(t.getClass())) { + if (null == t || !BeanUtil.isBean(t.getClass())) { // 非Bean放在同一子分组中 return 0; } diff --git a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java index 1e2962e184..99e0d0b10b 100755 --- a/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/core/collection/CollUtilTest.java @@ -9,6 +9,8 @@ import lombok.*; import org.junit.jupiter.api.Test; import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.*; @@ -323,7 +325,7 @@ public class CollUtilTest { public void filterTest2() { final ArrayList list = CollUtil.newArrayList("a", "b", "c"); - final ArrayList filtered = CollUtil.filter(list, t -> false == "a".equals(t)); + final ArrayList filtered = CollUtil.filter(list, t -> !"a".equals(t)); // 原地过滤 assertSame(list, filtered); @@ -1532,4 +1534,21 @@ public class CollUtilTest { assertNotNull(cat1); assertEquals("cat", cat1.getName()); } + + @Test + void issueIDBU9HTest(){ + List list = new ArrayList<>(); + ToolTest t1 = new ToolTest("a"); + ToolTest t2 = new ToolTest("b"); + list.add(t1); + list.add(t2); + Map map = list.stream().collect(Collectors.toMap(ToolTest::getName, Function.identity(), (k1, k2) -> k2)); + CollectionUtil.subtract(map.keySet(), map.keySet()); + } + + @Data + @AllArgsConstructor + private static class ToolTest { + private String name; + } }