添加 注释 并增加方法

This commit is contained in:
hbn.king 2021-11-02 10:21:49 +08:00
parent e779a9a74c
commit 8e5ed2b691

View File

@ -414,12 +414,31 @@ public class CollUtil {
* @param collection 集合 * @param collection 集合
* @param value 需要查找的值 * @param value 需要查找的值
* @return 如果集合为空null或者空返回{@code false}否则找到元素返回{@code true} * @return 如果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
* @throws ClassCastException 如果类型不一致会抛出转换异常
* @throws NullPointerException 当指定的元素 值为 null ,或集合类不支持null 时抛出该异常
* @see Collection#contains(Object)
* @since 4.1.10 * @since 4.1.10
*/ */
public static boolean contains(Collection<?> collection, Object value) { public static boolean contains(Collection<?> collection, Object value) {
return isNotEmpty(collection) && collection.contains(value); return isNotEmpty(collection) && collection.contains(value);
} }
/**
* 判断指定集合是否包含指定值如果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
* @param collection 集合
* @param value 需要查找的值
* @return 果集合为空null或者空返回{@code false}否则找到元素返回{@code true}
*/
public static boolean safeContains(Collection<?> collection, Object value) {
try {
return contains(collection ,value);
} catch (ClassCastException | NullPointerException e) {
return false;
}
}
/** /**
* 自定义函数判断集合是否包含某类值 * 自定义函数判断集合是否包含某类值
* *