优化ArrayUtil的空判断

This commit is contained in:
Looly 2023-03-10 22:06:41 +08:00
parent ee57e381b0
commit 4cc18740a3
3 changed files with 40 additions and 39 deletions

View File

@ -7,6 +7,7 @@
### 🐣新特性
* 【core 】 改进Calculator.conversion兼容乘法符号省略写法issue#2964@Github
* 【core 】 改进XmlUtil.xmlToBean支持xml转bean时父节点忽略大小写
* 【core 】 优化ArrayUtil的空判断pr#2969@Github
### 🐞Bug修复
* 【crypto】 修复NoSuchMethodError未捕获问题issue#2966@Github
@ -49,7 +50,7 @@
* 【core 】 修复StrUtil.split切分长度为0时的bugpr#944@Gitee
* 【core 】 修复ReUtil.delAll方法当 content 仅为空格时的问题issue#I6GIMT@Gitee
* 【core 】 修复ReUtil.delAll方法当 content 仅为空格时的问题issue#I6GIMT@Gitee
* 【core 】 修复Tailer文件内容跟随在调用stop后文件依旧被占用问题issue#I6GFD2@Gitee
* 【core 】 修复文件内容跟随在调用stop后文件依旧被占用问题issue#I6GFD2@Gitee
* 【core 】 修复ReflectUtil.invokeRaw方法中参数类型转换动作未生效的问题pr#2912@Github
* 【core 】 修复isXXX转换时的匹配问题issue#I6H0XF@Gitee
* 【core 】 修复MutableObj.equals空指针问题
@ -438,7 +439,7 @@
* 【core 】 修复SimpleCache线程安全问题
* 【core 】 修复ClassLoaderUtil中可能的关联ClassLoader错位问题
* 【extra 】 修复Sftp错误内容解析大小写问题issue#I53GPI@Gitee
* 【core 】 修复Tailer当文件内容为空时会报异常问题pr#602@Gitee
* 【core 】 修复当文件内容为空时会报异常问题pr#602@Gitee
-------------------------------------------------------------------------------------------------------------

View File

@ -553,16 +553,16 @@ public class ArrayUtil extends PrimitiveArrayUtil {
}
int length = 0;
for (T[] array : arrays) {
if (null != array) {
for (final T[] array : arrays) {
if (isNotEmpty(array)) {
length += array.length;
}
}
T[] result = newArray(arrays.getClass().getComponentType().getComponentType(), length);
final T[] result = newArray(arrays.getClass().getComponentType().getComponentType(), length);
length = 0;
for (T[] array : arrays) {
if (null != array) {
for (final T[] array : arrays) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}

View File

@ -220,7 +220,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (byte[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -228,7 +228,7 @@ public class PrimitiveArrayUtil {
final byte[] result = new byte[length];
length = 0;
for (byte[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -252,7 +252,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (int[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -260,7 +260,7 @@ public class PrimitiveArrayUtil {
final int[] result = new int[length];
length = 0;
for (int[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -284,7 +284,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (long[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -292,7 +292,7 @@ public class PrimitiveArrayUtil {
final long[] result = new long[length];
length = 0;
for (long[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -316,7 +316,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (double[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -324,7 +324,7 @@ public class PrimitiveArrayUtil {
final double[] result = new double[length];
length = 0;
for (double[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -348,7 +348,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (float[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -356,7 +356,7 @@ public class PrimitiveArrayUtil {
final float[] result = new float[length];
length = 0;
for (float[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -380,7 +380,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (char[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -388,7 +388,7 @@ public class PrimitiveArrayUtil {
final char[] result = new char[length];
length = 0;
for (char[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -412,7 +412,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (boolean[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -420,7 +420,7 @@ public class PrimitiveArrayUtil {
final boolean[] result = new boolean[length];
length = 0;
for (boolean[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -444,7 +444,7 @@ public class PrimitiveArrayUtil {
// 计算总长度
int length = 0;
for (short[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
length += array.length;
}
}
@ -452,7 +452,7 @@ public class PrimitiveArrayUtil {
final short[] result = new short[length];
length = 0;
for (short[] array : arrays) {
if (null != array) {
if (isNotEmpty(array)) {
System.arraycopy(array, 0, result, length, array.length);
length += array.length;
}
@ -559,7 +559,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(long[] array, long value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
@ -578,7 +578,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(long[] array, long value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (value == array[i]) {
return i;
@ -609,7 +609,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(int[] array, int value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
@ -628,7 +628,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(int[] array, int value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (value == array[i]) {
return i;
@ -659,7 +659,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(short[] array, short value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
@ -678,7 +678,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(short[] array, short value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (value == array[i]) {
return i;
@ -709,7 +709,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(char[] array, char value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
@ -728,7 +728,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(char[] array, char value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (value == array[i]) {
return i;
@ -759,7 +759,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(byte[] array, byte value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
@ -778,7 +778,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(byte[] array, byte value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (value == array[i]) {
return i;
@ -809,7 +809,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(double[] array, double value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (NumberUtil.equals(value, array[i])) {
return i;
@ -828,7 +828,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(double[] array, double value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (NumberUtil.equals(value, array[i])) {
return i;
@ -859,7 +859,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(float[] array, float value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (NumberUtil.equals(value, array[i])) {
return i;
@ -878,7 +878,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(float[] array, float value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (NumberUtil.equals(value, array[i])) {
return i;
@ -909,7 +909,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int indexOf(boolean[] array, boolean value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = 0; i < array.length; i++) {
if (value == array[i]) {
return i;
@ -928,7 +928,7 @@ public class PrimitiveArrayUtil {
* @since 3.0.7
*/
public static int lastIndexOf(boolean[] array, boolean value) {
if (null != array) {
if (isNotEmpty(array)) {
for (int i = array.length - 1; i >= 0; i--) {
if (value == array[i]) {
return i;