shimingxy пре 9 часа
родитељ
комит
fd76e2d7dd

+ 5 - 4
maxkey-commons/maxkey-common/src/main/java/org/dromara/maxkey/util/StrUtils.java

@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
 public final class StrUtils {
@@ -237,12 +238,12 @@ public final class StrUtils {
 
     public static List<String> string2List(String string, String split) {
         String[] strs = {};
-        if (string != null && !string.equals("")) {
+        if (StringUtils.isNotEmpty(string)) {
             strs = string.split(split);
         }
         ArrayList<String> resultList = new ArrayList<String>(0);
         for (int i = 0; i < strs.length; i++) {
-            if (strs[i] != null && !strs[i].equals("")) {
+            if (StringUtils.isNotEmpty(strs[i])) {
                 resultList.add(strs[i]);
             }
         }
@@ -252,11 +253,11 @@ public final class StrUtils {
 
     public static String list2String(List<String> list, String split) {
         String string = "";
-        if (list == null) {
+        if (CollectionUtils.isEmpty(list)) {
             return string;
         }
         for (int i = 0; i < list.size(); i++) {
-            if (list.get(i) != null && !list.get(i).equals("")) {
+            if (StringUtils.isNotEmpty(list.get(i))) {
                 string += list.get(i) + split;
             }
         }

+ 40 - 0
maxkey-commons/maxkey-common/src/test/java/org/maxkey/util/StrUtilsTest.java

@@ -0,0 +1,40 @@
+/*
+ * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ 
+
+package org.maxkey.util;
+
+import java.util.ArrayList;
+
+import org.dromara.maxkey.util.StrUtils;
+import org.junit.jupiter.api.Test;
+
+public class StrUtilsTest {
+    @Test
+    public void string2List()  {
+        System.out.println(StrUtils.string2List("a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,,,",","));
+    }
+    
+    @Test
+    public void list2String()  {
+        ArrayList<String> list = new ArrayList<>();
+        list.add("1");
+        list.add("2");
+        list.add("3");
+        list.add("");
+        System.out.println(StrUtils.list2String(list,","));
+    }
+}