From 787d7600be961fc023f92ec095c0706631c5139f Mon Sep 17 00:00:00 2001 From: YunaiV Date: Mon, 15 May 2023 21:41:11 +0800 Subject: [PATCH] =?UTF-8?q?!479=20StrUtils.maxLength=E4=BC=9A=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E7=BB=99=E5=90=8E=E9=9D=A2=E5=8A=A0=E4=B8=89=E4=B8=AA?= =?UTF-8?q?=E7=82=B9=EF=BC=8C=E5=93=AA=E6=80=95=E9=95=BF=E5=BA=A6=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=B6=85=E8=BF=87=EF=BC=8C=E4=BC=98=E5=8C=96=E9=95=BF?= =?UTF-8?q?=E5=BA=A6=E4=B8=8D=E8=B6=85=E8=BF=87=E4=B8=8D=E5=8A=A0...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/common/util/collection/SetUtils.java | 7 ++++--- .../yudao/framework/common/util/string/StrUtils.java | 10 +++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) 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 ec380032a..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; /** @@ -11,8 +11,9 @@ import java.util.Set; */ 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 3f79ceea6..53dabcac8 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; @@ -13,7 +14,14 @@ import java.util.Collection; 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 的原因,是该方法会补充 ... 恰好 } /**