From b2374e810bd13dfc9dc1d10319b59e59b08412e0 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 7 Jun 2023 10:45:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20StringUtils=20=E7=9A=84=20?= =?UTF-8?q?leftPad=20=E5=92=8C=20rightPad=20=E5=8D=B3=E5=8F=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/util/StrUtil.java | 34 ------------------- .../plusone/commons/util/StrUtilTests.java | 31 ----------------- 2 files changed, 65 deletions(-) delete mode 100644 src/main/java/xyz/zhouxy/plusone/commons/util/StrUtil.java delete mode 100644 src/test/java/xyz/zhouxy/plusone/commons/util/StrUtilTests.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/StrUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/StrUtil.java deleted file mode 100644 index b84f3a4..0000000 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/StrUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package xyz.zhouxy.plusone.commons.util; - -import java.util.Arrays; - -public class StrUtil { - - public static String fillBefore(String src, int minLength, char c) { - if (src.length() >= minLength) { - return src; - } - char[] result = new char[minLength]; - Arrays.fill(result, 0, minLength - src.length(), c); - for (int i = 1; i <= src.length(); i++) { - result[minLength - i] = src.charAt(src.length() - i); - } - return String.valueOf(result); - } - - public static String fillAfter(String src, int minLength, char c) { - if (src.length() >= minLength) { - return src; - } - char[] result = new char[minLength]; - for (int i = 0; i < src.length(); i++) { - result[i] = src.charAt(i); - } - Arrays.fill(result, src.length(), result.length, c); - return String.valueOf(result); - } - - private StrUtil() { - throw new IllegalStateException("Utility class"); - } -} diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/StrUtilTests.java b/src/test/java/xyz/zhouxy/plusone/commons/util/StrUtilTests.java deleted file mode 100644 index 2185544..0000000 --- a/src/test/java/xyz/zhouxy/plusone/commons/util/StrUtilTests.java +++ /dev/null @@ -1,31 +0,0 @@ -package xyz.zhouxy.plusone.commons.util; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -class StrUtilTests { - - private static final Logger log = LoggerFactory.getLogger(StrUtilTests.class); - - @Test - void testFillZero() { - char c = '='; - log.info(StrUtil.fillBefore("1", 6, c)); - log.info(StrUtil.fillBefore("12", 6, c)); - log.info(StrUtil.fillBefore("123", 6, c)); - log.info(StrUtil.fillBefore("1234", 6, c)); - log.info(StrUtil.fillBefore("12345", 6, c)); - log.info(StrUtil.fillBefore("123456", 6, c)); - log.info(StrUtil.fillBefore("1234567", 6, c)); - log.info(StrUtil.fillBefore("12345678", 6, c)); - log.info(StrUtil.fillAfter("1", 6, c)); - log.info(StrUtil.fillAfter("12", 6, c)); - log.info(StrUtil.fillAfter("123", 6, c)); - log.info(StrUtil.fillAfter("1234", 6, c)); - log.info(StrUtil.fillAfter("12345", 6, c)); - log.info(StrUtil.fillAfter("123456", 6, c)); - log.info(StrUtil.fillAfter("1234567", 6, c)); - log.info(StrUtil.fillAfter("12345678", 6, c)); - } -}