mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix code
This commit is contained in:
parent
c4420ae52a
commit
1765e82ef5
@ -12,6 +12,7 @@
|
||||
|
||||
package org.dromara.hutool.core.collection;
|
||||
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.bean.BeanUtil;
|
||||
import org.dromara.hutool.core.codec.hash.Hash32;
|
||||
import org.dromara.hutool.core.collection.iter.IterUtil;
|
||||
@ -25,9 +26,9 @@ import org.dromara.hutool.core.comparator.PropertyComparator;
|
||||
import org.dromara.hutool.core.convert.CompositeConverter;
|
||||
import org.dromara.hutool.core.convert.Convert;
|
||||
import org.dromara.hutool.core.exception.HutoolException;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.func.SerBiConsumer;
|
||||
import org.dromara.hutool.core.func.SerConsumer3;
|
||||
import org.dromara.hutool.core.lang.Assert;
|
||||
import org.dromara.hutool.core.map.MapUtil;
|
||||
import org.dromara.hutool.core.reflect.ConstructorUtil;
|
||||
import org.dromara.hutool.core.reflect.FieldUtil;
|
||||
@ -35,7 +36,6 @@ import org.dromara.hutool.core.reflect.TypeUtil;
|
||||
import org.dromara.hutool.core.stream.StreamUtil;
|
||||
import org.dromara.hutool.core.text.StrUtil;
|
||||
import org.dromara.hutool.core.text.split.SplitUtil;
|
||||
import org.dromara.hutool.core.array.ArrayUtil;
|
||||
import org.dromara.hutool.core.util.ObjUtil;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
@ -51,7 +51,6 @@ import java.util.stream.Collectors;
|
||||
* 集合相关工具类
|
||||
* <p>
|
||||
* 此工具方法针对{@link Collection}或{@link Iterable}及其实现类封装的工具。
|
||||
* <p>
|
||||
*
|
||||
* @author Looly
|
||||
* @see IterUtil
|
||||
@ -2321,4 +2320,33 @@ public class CollUtil {
|
||||
return collection.add(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否至少有一个符合判断条件
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param collection 集合
|
||||
* @param predicate 自定义判断函数
|
||||
* @return 是否有一个值匹配 布尔值
|
||||
*/
|
||||
public static <T> boolean anyMatch(final Collection<T> collection, final Predicate<T> predicate) {
|
||||
if (isEmpty(collection)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
return collection.stream().anyMatch(predicate);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否全部匹配判断条件
|
||||
*
|
||||
* @param <T> 集合元素类型
|
||||
* @param collection 集合
|
||||
* @param predicate 自定义判断函数
|
||||
* @return 是否全部匹配 布尔值
|
||||
*/
|
||||
public static <T> boolean allMatch(final Collection<T> collection, final Predicate<T> predicate) {
|
||||
if (isEmpty(collection)) {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
return collection.stream().allMatch(predicate);
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +137,7 @@ public class CollUtilTest {
|
||||
Assertions.assertEquals(srcList, answerList);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantValue")
|
||||
@Test
|
||||
public void isNotEmptyTest() {
|
||||
Assertions.assertFalse(CollUtil.isNotEmpty((Collection<?>) null));
|
||||
@ -505,9 +506,9 @@ public class CollUtilTest {
|
||||
);
|
||||
|
||||
final Map<String, Integer> map = CollUtil.fieldValueAsMap(list, "name", "age");
|
||||
Assertions.assertEquals(new Integer(12), map.get("张三"));
|
||||
Assertions.assertEquals(new Integer(13), map.get("李四"));
|
||||
Assertions.assertEquals(new Integer(14), map.get("王五"));
|
||||
Assertions.assertEquals(Integer.valueOf(12), map.get("张三"));
|
||||
Assertions.assertEquals(Integer.valueOf(13), map.get("李四"));
|
||||
Assertions.assertEquals(Integer.valueOf(14), map.get("王五"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -1153,4 +1154,13 @@ public class CollUtilTest {
|
||||
Assertions.assertFalse(CollUtil.isEqualList(list, ListUtil.of(1, 2, 3)));
|
||||
Assertions.assertFalse(CollUtil.isEqualList(list, ListUtil.of(4, 3, 2, 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatch() {
|
||||
final List<Integer> list = Arrays.asList(1, 2, 3, 4, 5, 6);
|
||||
Assertions.assertTrue(CollUtil.anyMatch(list, i -> i == 1));
|
||||
Assertions.assertFalse(CollUtil.anyMatch(list, i -> i > 6));
|
||||
Assertions.assertFalse(CollUtil.allMatch(list, i -> i == 1));
|
||||
Assertions.assertTrue(CollUtil.allMatch(list, i -> i <= 6));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user