From 8b249fb79f71617781a9e5f2fe652da2a7d71b7c Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Wed, 21 Aug 2019 11:26:44 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0arrayKit=E5=86=85?= =?UTF-8?q?=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fanruan/api/util/ArrayKit.java | 40 +++++++ .../com/fanruan/api/util/ArrayKitTest.java | 101 ++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 src/test/java/com/fanruan/api/util/ArrayKitTest.java diff --git a/src/main/java/com/fanruan/api/util/ArrayKit.java b/src/main/java/com/fanruan/api/util/ArrayKit.java index 34cb26e..792aa3a 100644 --- a/src/main/java/com/fanruan/api/util/ArrayKit.java +++ b/src/main/java/com/fanruan/api/util/ArrayKit.java @@ -1,9 +1,49 @@ package com.fanruan.api.util; +import java.io.IOException; +import java.lang.reflect.Array; +import com.fr.stable.ArrayUtils; + /** * @author richie * @version 10.0 * Created by richie on 2019-08-16 */ public class ArrayKit { + public static final String[] EMPTY_STRING_ARRAY = new String[0]; + /** + * 判断数组是否为空 + * + * @param array 源数组 + * @return 返回数组判断为空的结果 + */ + public static boolean isEmpty(Object[] array) { + return ArrayUtils.isEmpty(array); + } + /** + * 移除目标数组中对应下标的元素 + * + * @param array 源数组 + * @param number 要移除的元素的下标 + * @return 返回移除元素后的数组 + */ + public static T[] remove(T[] array, int number) { + return ArrayUtils.remove(array, number); + } + /** + * 给目标数组中增加单个元素 + * + * @param array 源数组 + * @param element 要增加的元素 + * @return 返回增加元素后的数组 + */ + public static T[] add(T[] array, T element) {return ArrayUtils.add(array, element);}; + /** + * 给目标数组中增加多个元素 + * + * @param array 源数组 + * @param element 要增加的元素 + * @return 返回增加元素后的数组 + */ + public static T[] addAll(T[] array, T... element){return ArrayUtils.addAll(array, element);}; } diff --git a/src/test/java/com/fanruan/api/util/ArrayKitTest.java b/src/test/java/com/fanruan/api/util/ArrayKitTest.java new file mode 100644 index 0000000..d63d080 --- /dev/null +++ b/src/test/java/com/fanruan/api/util/ArrayKitTest.java @@ -0,0 +1,101 @@ +package com.fanruan.api.util; +import com.fr.general.Inter; +import com.fr.stable.ArrayUtils; +import com.fanruan.api.Prepare; +import org.junit.Assert; +import org.junit.Test; + +public class ArrayKitTest extends Prepare { + @Test + public void isEmpty() throws Exception{ + Object emptyArray []=new Object[0]; + Object notEmptyArray [] = new Object[1]; + Assert.assertEquals(ArrayKit.isEmpty(emptyArray), true); + Assert.assertEquals(ArrayKit.isEmpty(notEmptyArray), false); + + } + + @Test + public void remove() throws Exception{ + Integer intTestArray [] = {1,2,3,4}; + Integer intTestResult [] = {1,2,3}; + Boolean booleanTestArray [] = {true, true, true, false}; + Boolean booleanTestResult [] = {true, true, true}; + Byte byteTestArray [] = {100,101,102,103}; + Byte byteTestResult [] = {100,101,102}; + Character charTestArray [] = {'a','b','c','d'}; + Character charTestResult [] = {'a','b','c'}; + Double doubleTestArray [] = {1.1,2.2,3.3,4.4}; + Double doubleTestResult [] = {1.1,2.2,3.3}; + Float floatTestArray [] = {1.1f,2.2f,3.3f,4.4f}; + Float floatTestResult [] = {1.1f,2.2f,3.3f}; + Long longTestArray [] = {1L,2L,3L,4L}; + Long longTestResult [] = {1L,2L,3L}; + Short shortTestArray [] = {1,2,3,4}; + Short shortTestResult [] = {1,2,3}; + Assert.assertEquals(ArrayKit.remove(intTestArray, 3), intTestResult); + Assert.assertEquals(ArrayKit.remove(booleanTestArray, 3), booleanTestResult); + Assert.assertEquals(ArrayKit.remove(byteTestArray, 3), byteTestResult); + Assert.assertEquals(ArrayKit.remove(charTestArray, 3), charTestResult); + Assert.assertEquals(ArrayKit.remove(doubleTestArray, 3), doubleTestResult); + Assert.assertEquals(ArrayKit.remove(floatTestArray, 3), floatTestResult); + Assert.assertEquals(ArrayKit.remove(longTestArray, 3), longTestResult); + Assert.assertEquals(ArrayKit.remove(shortTestArray, 3), shortTestResult); + } + + @Test + public void add() throws Exception{ + Integer intTestArray [] = {1,2,3,4}; + Integer intTestResult [] = {1,2,3,4,5}; + Boolean booleanTestArray [] = {true, true, true, false}; + Boolean booleanTestResult [] = {true, true, true, false, true}; + Byte byteTestArray [] = {1}; + Byte byteTestResult [] = {1,0}; + Character charTestArray [] = {'a','b','c','d'}; + Character charTestResult [] = {'a','b','c','d','e'}; + Double doubleTestArray [] = {1.1,2.2,3.3,4.4}; + Double doubleTestResult [] = {1.1,2.2,3.3,4.4,5.5}; + Float floatTestArray [] = {1.1f,2.2f,3.3f,4.4f}; + Float floatTestResult [] = {1.1f,2.2f,3.3f,4.4f,5.5f}; + Long longTestArray [] = {1L,2L,3L,4L}; + Long longTestResult [] = {1L,2L,3L,4L,5L}; + Short shortTestArray [] = {1,2,3,4}; + Short shortTestResult [] = {1,2,3,4,5}; + Assert.assertEquals(ArrayKit.add(intTestArray, 5), intTestResult); + Assert.assertEquals(ArrayKit.add(booleanTestArray, true), booleanTestResult); + Assert.assertEquals(ArrayKit.add(byteTestArray, new Byte("0")), byteTestResult); + Assert.assertEquals(ArrayKit.add(charTestArray, 'e'), charTestResult); + Assert.assertEquals(ArrayKit.add(doubleTestArray, 5.5), doubleTestResult); + Assert.assertEquals(ArrayKit.add(floatTestArray, 5.5f), floatTestResult); + Assert.assertEquals(ArrayKit.add(longTestArray, 5L), longTestResult); + Assert.assertEquals(ArrayKit.add(shortTestArray, new Short("5")), shortTestResult); + } + + @Test + public void addAll() throws Exception{ + Integer intTestArray [] = {1,2,3,4}; + Integer intTestResult [] = {1,2,3,4,5,6}; + Boolean booleanTestArray [] = {true, true, true, false}; + Boolean booleanTestResult [] = {true, true, true, false, true,true}; + Byte byteTestArray [] = {1}; + Byte byteTestResult [] = {1,0,0}; + Character charTestArray [] = {'a','b','c','d'}; + Character charTestResult [] = {'a','b','c','d','e','f'}; + Double doubleTestArray [] = {1.1,2.2,3.3,4.4}; + Double doubleTestResult [] = {1.1,2.2,3.3,4.4,5.5,6.6}; + Float floatTestArray [] = {1.1f,2.2f,3.3f,4.4f}; + Float floatTestResult [] = {1.1f,2.2f,3.3f,4.4f,5.5f,6.6f}; + Long longTestArray [] = {1L,2L,3L,4L}; + Long longTestResult [] = {1L,2L,3L,4L,5L,6L}; + Short shortTestArray [] = {1,2,3,4}; + Short shortTestResult [] = {1,2,3,4,5,6}; + Assert.assertEquals(ArrayKit.addAll(intTestArray, 5,6), intTestResult); + Assert.assertEquals(ArrayKit.addAll(booleanTestArray, true, true), booleanTestResult); + Assert.assertEquals(ArrayKit.addAll(byteTestArray, new Byte("0"), new Byte("0")), byteTestResult); + Assert.assertEquals(ArrayKit.addAll(charTestArray, 'e','f'), charTestResult); + Assert.assertEquals(ArrayKit.addAll(doubleTestArray, 5.5,6.6), doubleTestResult); + Assert.assertEquals(ArrayKit.addAll(floatTestArray, 5.5f,6.6f), floatTestResult); + Assert.assertEquals(ArrayKit.addAll(longTestArray, 5L,6L), longTestResult); + Assert.assertEquals(ArrayKit.addAll(shortTestArray, new Short("5"),new Short("6")), shortTestResult); + } +} From aec68abc8abbda15dcca499f986f8892bc6cca53 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Wed, 21 Aug 2019 16:11:24 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat:=E5=AF=B9stringkit=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E8=A1=A5=E5=85=85=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=9B=B8=E5=BA=94=E7=9A=84=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fanruan/api/util/StringKit.java | 9 +++++++++ src/test/java/com/fanruan/api/util/StringKitTest.java | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/com/fanruan/api/util/StringKit.java b/src/main/java/com/fanruan/api/util/StringKit.java index f3e47df..e79d263 100644 --- a/src/main/java/com/fanruan/api/util/StringKit.java +++ b/src/main/java/com/fanruan/api/util/StringKit.java @@ -85,5 +85,14 @@ public class StringKit { public static boolean isNotBlank(String text) { return StringUtils.isNotBlank(text); } + /** + * 对字符串做trim操作 + * + * @param string 源字符串 + * @return 返回操作后的字符串 + */ + public static String trim(String string) { + return StringUtils.trim(string); + } } diff --git a/src/test/java/com/fanruan/api/util/StringKitTest.java b/src/test/java/com/fanruan/api/util/StringKitTest.java index be66448..3e07b43 100644 --- a/src/test/java/com/fanruan/api/util/StringKitTest.java +++ b/src/test/java/com/fanruan/api/util/StringKitTest.java @@ -1,5 +1,6 @@ package com.fanruan.api.util; +import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.*; @@ -26,4 +27,13 @@ public class StringKitTest { @Test public void isNotBlank() { } + @Test + public void trim(){ + String stringHaveBlank = " abc "; + String stringWithoutBlank = "abc"; + String blankString = " "; + Assert.assertEquals(StringKit.trim(stringHaveBlank), "abc"); + Assert.assertEquals(StringKit.trim(stringWithoutBlank), "abc"); + Assert.assertEquals(StringKit.trim(blankString), ""); + } } \ No newline at end of file From 20cad8dcad923c4288a09899f5eff94fc853b934 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Wed, 21 Aug 2019 16:39:07 +0800 Subject: [PATCH 3/3] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=B8=B8?= =?UTF-8?q?=E9=87=8F=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fanruan/constants/Constants.java | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/main/java/com/fanruan/constants/Constants.java diff --git a/src/main/java/com/fanruan/constants/Constants.java b/src/main/java/com/fanruan/constants/Constants.java new file mode 100644 index 0000000..ea4b5e0 --- /dev/null +++ b/src/main/java/com/fanruan/constants/Constants.java @@ -0,0 +1,6 @@ +package com.fanruan.constants; +import com.fr.stable.EncodeConstants; + +public class Constants { + public static final String ENCODING_UTF_8 = EncodeConstants.ENCODING_UTF_8; +}