mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
add test
This commit is contained in:
@@ -575,7 +575,7 @@ public class CollUtil {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (false == foundCurrentElement) {
|
if (!foundCurrentElement) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1805,7 +1805,7 @@ public class CollUtil {
|
|||||||
* @return 是否为空
|
* @return 是否为空
|
||||||
*/
|
*/
|
||||||
public static boolean isEmpty(Enumeration<?> enumeration) {
|
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 <T> List<T> addAllIfNotContains(List<T> list, List<T> otherList) {
|
public static <T> List<T> addAllIfNotContains(List<T> list, List<T> otherList) {
|
||||||
for (T t : otherList) {
|
for (T t : otherList) {
|
||||||
if (false == list.contains(t)) {
|
if (!list.contains(t)) {
|
||||||
list.add(t);
|
list.add(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2841,7 +2841,7 @@ public class CollUtil {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hash32(T t) {
|
public int hash32(T t) {
|
||||||
if (null == t || false == BeanUtil.isBean(t.getClass())) {
|
if (null == t || !BeanUtil.isBean(t.getClass())) {
|
||||||
// 非Bean放在同一子分组中
|
// 非Bean放在同一子分组中
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import lombok.*;
|
|||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@@ -323,7 +325,7 @@ public class CollUtilTest {
|
|||||||
public void filterTest2() {
|
public void filterTest2() {
|
||||||
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
final ArrayList<String> list = CollUtil.newArrayList("a", "b", "c");
|
||||||
|
|
||||||
final ArrayList<String> filtered = CollUtil.filter(list, t -> false == "a".equals(t));
|
final ArrayList<String> filtered = CollUtil.filter(list, t -> !"a".equals(t));
|
||||||
|
|
||||||
// 原地过滤
|
// 原地过滤
|
||||||
assertSame(list, filtered);
|
assertSame(list, filtered);
|
||||||
@@ -1532,4 +1534,21 @@ public class CollUtilTest {
|
|||||||
assertNotNull(cat1);
|
assertNotNull(cat1);
|
||||||
assertEquals("cat", cat1.getName());
|
assertEquals("cat", cat1.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void issueIDBU9HTest(){
|
||||||
|
List<ToolTest> list = new ArrayList<>();
|
||||||
|
ToolTest t1 = new ToolTest("a");
|
||||||
|
ToolTest t2 = new ToolTest("b");
|
||||||
|
list.add(t1);
|
||||||
|
list.add(t2);
|
||||||
|
Map<String, ToolTest> 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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user