From e40f07fc643832786e353da2c515597437f27260 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Mon, 5 Jun 2023 18:27:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20MoreArrays=20=E7=B1=BB?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/util/MoreArrays.java | 29 +++++++++++++++++++ .../plusone/commons/util/MoreArraysTests.java | 20 +++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java create mode 100644 src/test/java/xyz/zhouxy/plusone/commons/util/MoreArraysTests.java diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java new file mode 100644 index 0000000..4291478 --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/MoreArrays.java @@ -0,0 +1,29 @@ +package xyz.zhouxy.plusone.commons.util; + +import java.util.Arrays; + +import com.google.common.annotations.Beta; + +@Beta +public class MoreArrays { + + public static Object[] asObjectArray(final Object... objects) { + return objects; + } + + public static char[] newCharArrayWith(int length, char c) { + char[] arr = new char[length]; + Arrays.fill(arr, c); + return arr; + } + + public static String[] newStringArrayWith(int length, String c) { + String[] arr = new String[length]; + Arrays.fill(arr, c); + return arr; + } + + private MoreArrays() { + throw new IllegalStateException("Utility class"); + } +} diff --git a/src/test/java/xyz/zhouxy/plusone/commons/util/MoreArraysTests.java b/src/test/java/xyz/zhouxy/plusone/commons/util/MoreArraysTests.java new file mode 100644 index 0000000..bca55a7 --- /dev/null +++ b/src/test/java/xyz/zhouxy/plusone/commons/util/MoreArraysTests.java @@ -0,0 +1,20 @@ +package xyz.zhouxy.plusone.commons.util; + +import java.util.Arrays; +import java.util.Date; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +class MoreArraysTests { + + private static final Logger log = LoggerFactory.getLogger(MoreArraysTests.class); + + @Test + void testAsObjectArray() { + Object[] arr = MoreArrays.asObjectArray("1", "2", 1, 2, new Date()); + log.info("arr: {}", arr.toString()); + log.info("arr: {}", Arrays.toString(arr)); + } +}