forked from plusone/plusone-commons
添加 MoreArrays 类。
parent
1434074ced
commit
e40f07fc64
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue