mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
add allAll for primitive
This commit is contained in:
parent
32ece1bbf4
commit
5a99c64226
@ -31,6 +31,7 @@
|
|||||||
* 【http 】 HttpUtil增加downloadBytes方法(pr#895@Github)
|
* 【http 】 HttpUtil增加downloadBytes方法(pr#895@Github)
|
||||||
* 【core 】 isMactchRegex失效标记,增加isMatchRegex(issue#I1IPJG@Gitee)
|
* 【core 】 isMactchRegex失效标记,增加isMatchRegex(issue#I1IPJG@Gitee)
|
||||||
* 【core 】 优化Validator.isChinese
|
* 【core 】 优化Validator.isChinese
|
||||||
|
* 【core 】 ArrayUtil.addAll增加原始类型支持(issue#898@Github)
|
||||||
|
|
||||||
### Bug修复
|
### Bug修复
|
||||||
* 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee)
|
* 【core 】 修复SimpleCache死锁问题(issue#I1HOKB@Gitee)
|
||||||
|
@ -654,6 +654,230 @@ public class ArrayUtil {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static int[] addAll(int[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (int[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final int[] result = new int[length];
|
||||||
|
length = 0;
|
||||||
|
for (int[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static long[] addAll(long[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (long[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final long[] result = new long[length];
|
||||||
|
length = 0;
|
||||||
|
for (long[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static double[] addAll(double[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (double[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final double[] result = new double[length];
|
||||||
|
length = 0;
|
||||||
|
for (double[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static float[] addAll(float[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (float[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final float[] result = new float[length];
|
||||||
|
length = 0;
|
||||||
|
for (float[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static char[] addAll(char[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (char[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final char[] result = new char[length];
|
||||||
|
length = 0;
|
||||||
|
for (char[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static boolean[] addAll(boolean[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (boolean[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final boolean[] result = new boolean[length];
|
||||||
|
length = 0;
|
||||||
|
for (boolean[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将多个数组合并在一起<br>
|
||||||
|
* 忽略null的数组
|
||||||
|
*
|
||||||
|
* @param arrays 数组集合
|
||||||
|
* @return 合并后的数组
|
||||||
|
* @since 4.6.9
|
||||||
|
*/
|
||||||
|
public static short[] addAll(short[]... arrays) {
|
||||||
|
if (arrays.length == 1) {
|
||||||
|
return arrays[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 计算总长度
|
||||||
|
int length = 0;
|
||||||
|
for (short[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final short[] result = new short[length];
|
||||||
|
length = 0;
|
||||||
|
for (short[] array : arrays) {
|
||||||
|
if (null != array) {
|
||||||
|
System.arraycopy(array, 0, result, length, array.length);
|
||||||
|
length += array.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 包装 {@link System#arraycopy(Object, int, Object, int, int)}<br>
|
* 包装 {@link System#arraycopy(Object, int, Object, int, int)}<br>
|
||||||
* 数组复制
|
* 数组复制
|
||||||
|
@ -283,4 +283,10 @@ public class ArrayUtilTest {
|
|||||||
Assert.assertEquals("C", array[2]);
|
Assert.assertEquals("C", array[2]);
|
||||||
Assert.assertEquals("D", array[3]);
|
Assert.assertEquals("D", array[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addAllTest(){
|
||||||
|
final int[] ints = ArrayUtil.addAll(new int[]{1, 2, 3}, new int[]{4, 5, 6});
|
||||||
|
Assert.assertArrayEquals(new int[]{1,2,3,4,5,6}, ints);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user