diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/SetUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/SetUtils.java index bc5bc5cb8..e8eba6624 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/SetUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/SetUtils.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.framework.common.util.collection; -import java.util.Arrays; -import java.util.HashSet; +import cn.hutool.core.collection.CollUtil; + import java.util.Set; /** @@ -13,7 +13,7 @@ public class SetUtils { @SafeVarargs public static Set asSet(T... objs) { - return new HashSet<>(Arrays.asList(objs)); + return CollUtil.newHashSet(objs); } } diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java index 88ba22d87..46539082c 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/string/StrUtils.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.common.util.string; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ArrayUtil; import cn.hutool.core.util.StrUtil; @@ -16,7 +17,14 @@ import java.util.stream.Collectors; public class StrUtils { public static String maxLength(CharSequence str, int maxLength) { - return StrUtil.maxLength(str, maxLength - 3); // -3 的原因,是该方法会补充 ... 恰好 + Assert.isTrue(maxLength > 0); + if (null == str) { + return null; + } + if (str.length() <= maxLength) { + return str.toString(); + } + return StrUtil.sub(str, 0, maxLength - 3) + "..."; // -3 的原因,是该方法会补充 ... 恰好 } /** @@ -45,4 +53,7 @@ public class StrUtils { return Arrays.stream(longs).boxed().collect(Collectors.toList()); } + public static void main(String[] args) { + System.out.println(maxLength("aaaaa", 4)); + } }