add method

This commit is contained in:
Looly
2020-10-23 21:49:29 +08:00
parent 30695b906b
commit 1b90832f91
4 changed files with 20 additions and 14 deletions

View File

@@ -511,7 +511,7 @@ public class FileUtil extends PathUtil {
* @return 总大小bytes长度
*/
public static long size(File file) {
if (null == file || false == file.exists() || FileUtil.isSymlink(file)) {
if (null == file || false == file.exists() || isSymlink(file)) {
return 0;
}

View File

@@ -5,7 +5,7 @@ import cn.hutool.core.util.ReUtil;
import java.util.regex.Pattern;
/**
* 常用正则表达式集合
* 常用正则表达式集合,更多正则见:https://any86.github.io/any-rule/
*
* @author Looly
*/

View File

@@ -62,8 +62,8 @@ public class ObjectUtil {
* @see Objects#equals(Object, Object)
*/
public static boolean equal(Object obj1, Object obj2) {
if(obj1 instanceof BigDecimal && obj2 instanceof BigDecimal){
return NumberUtil.equals((BigDecimal)obj1, (BigDecimal)obj2);
if (obj1 instanceof BigDecimal && obj2 instanceof BigDecimal) {
return NumberUtil.equals((BigDecimal) obj1, (BigDecimal) obj2);
}
return Objects.equals(obj1, obj2);
}
@@ -305,13 +305,15 @@ public class ObjectUtil {
/**
* 如果给定对象为{@code null} 返回默认值, 如果不为null 返回自定义handle处理后的返回值
* @param source Object 类型对象
* @param handle 自定义的处理方法
*
* @param source Object 类型对象
* @param handle 自定义的处理方法
* @param defaultValue 默认为空的返回值
* @param <T> 被检查对象为{@code null}返回默认值否则返回自定义handle处理后的返回值
* @return
* @param <T> 被检查对象为{@code null}返回默认值否则返回自定义handle处理后的返回值
* @return 处理后的返回值
* @since 5.4.6
*/
public static <T> T defaultIfNull(final Object source, Supplier<? extends T> handle, final T defaultValue) {
public static <T> T defaultIfNull(Object source, Supplier<? extends T> handle, final T defaultValue) {
if (Objects.nonNull(source)) {
return handle.get();
}
@@ -320,13 +322,15 @@ public class ObjectUtil {
/**
* 如果给定对象为{@code null}或者""返回默认值, 否则返回自定义handle处理后的返回值
* @param str String 类型
* @param handle 自定义的处理方法
*
* @param str String 类型
* @param handle 自定义的处理方法
* @param defaultValue 默认为空的返回值
* @param <T> 被检查对象为{@code null}或者 ""返回默认值否则返回自定义handle处理后的返回值
* @return
* @param <T> 被检查对象为{@code null}或者 ""返回默认值否则返回自定义handle处理后的返回值
* @return 处理后的返回值
* @since 5.4.6
*/
public static <T> T defaultIfEmpty(final String str, Supplier<? extends T> handle, final T defaultValue) {
public static <T> T defaultIfEmpty(String str, Supplier<? extends T> handle, final T defaultValue) {
if (StrUtil.isNotEmpty(str)) {
return handle.get();
}