修改注释

This commit is contained in:
zhouxy108 2024-10-21 18:18:53 +08:00
parent 66d0e811f7
commit e5cd981508
2 changed files with 66 additions and 27 deletions

View File

@ -26,18 +26,23 @@ import javax.annotation.Nullable;
public class ArrayTools { public class ArrayTools {
// empty arrays // #region - empty arrays
public static final char[] EMPTY_CHAR_ARRAY = {}; public static final char[] EMPTY_CHAR_ARRAY = {};
public static final int[] EMPTY_INTEGER_ARRAY = {}; public static final int[] EMPTY_INTEGER_ARRAY = {};
public static final long[] EMPTY_LONG_ARRAY = {}; public static final long[] EMPTY_LONG_ARRAY = {};
public static final float[] EMPTY_FLOAT_ARRAY = {}; public static final float[] EMPTY_FLOAT_ARRAY = {};
public static final double[] EMPTY_DOUBLE_ARRAY = {}; public static final double[] EMPTY_DOUBLE_ARRAY = {};
// #endregion
// #region - isNullOrEmpty
// isNullOrEmpty // isNullOrEmpty
/** /**
* 检查给定数组是否为空 * 检查给定数组是否为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @param <T> 数组中元素的类型 * @param <T> 数组中元素的类型
* @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false} * @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false}
@ -49,7 +54,7 @@ public class ArrayTools {
// isNullOrEmpty - float // isNullOrEmpty - float
/** /**
* 检查给定数组是否为空 * 检查给定数组是否为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false} * @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -60,7 +65,7 @@ public class ArrayTools {
// isNullOrEmpty - double // isNullOrEmpty - double
/** /**
* 检查给定数组是否为空 * 检查给定数组是否为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false} * @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -71,7 +76,7 @@ public class ArrayTools {
// isNullOrEmpty - byte // isNullOrEmpty - byte
/** /**
* 检查给定数组是否为空 * 检查给定数组是否为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false} * @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -82,7 +87,7 @@ public class ArrayTools {
// isNullOrEmpty - long // isNullOrEmpty - long
/** /**
* 检查给定数组是否为空 * 检查给定数组是否为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false} * @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -93,7 +98,7 @@ public class ArrayTools {
// isNullOrEmpty - int // isNullOrEmpty - int
/** /**
* 检查给定数组是否为空 * 检查给定数组是否为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false} * @return 如果数组为 {@code null} 或长度为 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -101,10 +106,14 @@ public class ArrayTools {
return arr == null || arr.length == 0; return arr == null || arr.length == 0;
} }
// #endregion
// #region - isNotEmpty
// isNotEmpty // isNotEmpty
/** /**
* 检查给定数组是否不为空 * 检查给定数组是否不为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @param <T> 数组中元素的类型 * @param <T> 数组中元素的类型
* @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false} * @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false}
@ -116,7 +125,7 @@ public class ArrayTools {
// isNotEmpty - float // isNotEmpty - float
/** /**
* 检查给定数组是否不为空 * 检查给定数组是否不为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false} * @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -127,7 +136,7 @@ public class ArrayTools {
// isNotEmpty - double // isNotEmpty - double
/** /**
* 检查给定数组是否不为空 * 检查给定数组是否不为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false} * @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -138,7 +147,7 @@ public class ArrayTools {
// isNotEmpty - byte // isNotEmpty - byte
/** /**
* 检查给定数组是否不为空 * 检查给定数组是否不为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false} * @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -149,7 +158,7 @@ public class ArrayTools {
// isNotEmpty - long // isNotEmpty - long
/** /**
* 检查给定数组是否不为空 * 检查给定数组是否不为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false} * @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -160,7 +169,7 @@ public class ArrayTools {
// isNotEmpty - int // isNotEmpty - int
/** /**
* 检查给定数组是否不为空 * 检查给定数组是否不为空
* *
* @param arr 待检查的数组可以为 {@code null} * @param arr 待检查的数组可以为 {@code null}
* @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false} * @return 如果数组不为 {@code null} 且长度大于 0则返回 {@code true}否则返回 {@code false}
*/ */
@ -168,7 +177,9 @@ public class ArrayTools {
return arr != null && arr.length > 0; return arr != null && arr.length > 0;
} }
// isAllElementsNotNull // #endregion
// #region - isAllElementsNotNull
/** /**
* 判断数组的所有元素是否都不为空 * 判断数组的所有元素是否都不为空
@ -178,11 +189,11 @@ public class ArrayTools {
* <li><b>数组中有至少一个元素为 {@code null}</b>返回 {@code false} * <li><b>数组中有至少一个元素为 {@code null}</b>返回 {@code false}
* <li><b>数组中所有元素都不为 {@code null}</b>返回 {@code true} * <li><b>数组中所有元素都不为 {@code null}</b>返回 {@code true}
* </ol> * </ol>
* *
* @param <T> 数组元素的类型 * @param <T> 数组元素的类型
* @param arr 待检查的数组不为 {@code null} * @param arr 待检查的数组不为 {@code null}
* @return 如果数组的所有元素都不为 {@code null}则返回 {@code true}否则返回 {@code false} * @return 如果数组的所有元素都不为 {@code null}则返回 {@code true}否则返回 {@code false}
* *
* @throws IllegalArgumentException 当参数为空时抛出 * @throws IllegalArgumentException 当参数为空时抛出
*/ */
public static <T> boolean isAllElementsNotNull(@Nonnull final T[] arr) { public static <T> boolean isAllElementsNotNull(@Nonnull final T[] arr) {
@ -195,11 +206,13 @@ public class ArrayTools {
return true; return true;
} }
// concat // #endregion
// #region - concat
/** /**
* 拼接多个数组 * 拼接多个数组
* *
* @param arrays 数组集合可以为 {@code null} * @param arrays 数组集合可以为 {@code null}
* @return 拼接后的数组 * @return 拼接后的数组
*/ */
@ -219,7 +232,7 @@ public class ArrayTools {
/** /**
* 拼接多个数组 * 拼接多个数组
* *
* @param arrays 数组集合可以为 {@code null} * @param arrays 数组集合可以为 {@code null}
* @return 拼接后的数组 * @return 拼接后的数组
*/ */
@ -239,7 +252,7 @@ public class ArrayTools {
/** /**
* 拼接多个数组 * 拼接多个数组
* *
* @param arrays 数组集合可以为 {@code null} * @param arrays 数组集合可以为 {@code null}
* @return 拼接后的数组 * @return 拼接后的数组
*/ */
@ -259,7 +272,7 @@ public class ArrayTools {
/** /**
* 拼接多个数组 * 拼接多个数组
* *
* @param arrays 数组集合可以为 {@code null} * @param arrays 数组集合可以为 {@code null}
* @return 拼接后的数组 * @return 拼接后的数组
*/ */
@ -279,7 +292,7 @@ public class ArrayTools {
/** /**
* 拼接多个数组 * 拼接多个数组
* *
* @param arrays 数组集合可以为 {@code null} * @param arrays 数组集合可以为 {@code null}
* @return 拼接后的数组 * @return 拼接后的数组
*/ */
@ -299,7 +312,7 @@ public class ArrayTools {
/** /**
* 将集合中的数组连接为一个列表 * 将集合中的数组连接为一个列表
* *
* @param arrays 可能包含多个数组的集合这些数组中的元素将被连接到一个列表中 * @param arrays 可能包含多个数组的集合这些数组中的元素将被连接到一个列表中
* @param <T> 泛型参数表示数组的元素类型 * @param <T> 泛型参数表示数组的元素类型
* @return 返回连接后的列表如果输入的集合为空或包含空数组则返回空列表 * @return 返回连接后的列表如果输入的集合为空或包含空数组则返回空列表
@ -322,6 +335,10 @@ public class ArrayTools {
return result; return result;
} }
// #endregion
// #region - fill
// fill - char // fill - char
public static void fill(char[] a, char... values) { public static void fill(char[] a, char... values) {
@ -451,7 +468,7 @@ public class ArrayTools {
public static <T> void fill(@Nonnull T[] a, int fromIndex, int toIndex, T[] values) { public static <T> void fill(@Nonnull T[] a, int fromIndex, int toIndex, T[] values) {
fillInternal(a, fromIndex, toIndex, values); fillInternal(a, fromIndex, toIndex, values);
} }
private static <T> void fillInternal(@Nonnull T[] a, int fromIndex, int toIndex, @Nullable T[] values) { private static <T> void fillInternal(@Nonnull T[] a, int fromIndex, int toIndex, @Nullable T[] values) {
AssertTools.checkArgumentNotNull(a); AssertTools.checkArgumentNotNull(a);
if (values == null || values.length == 0) { if (values == null || values.length == 0) {
@ -475,7 +492,13 @@ public class ArrayTools {
} }
} }
// #endregion
// #region - private constructor
private ArrayTools() { private ArrayTools() {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
// #endregion
} }

View File

@ -22,22 +22,24 @@ import javax.annotation.Nonnull;
/** /**
* 断言工具 * 断言工具
* *
* <p> * <p>
* 本工具类基本仅对表达式进行判断并在表达式为 {@code false} 时抛出对应异常 * 本工具类基本仅对表达式进行判断并在表达式为 {@code false} 时抛出对应异常
* 不封装过多判断逻辑鼓励充分使用项目中的工具类进行逻辑判断 * 不封装过多判断逻辑鼓励充分使用项目中的工具类进行逻辑判断
* </p> * </p>
* *
* <pre> * <pre>
* AssertTools.checkArgument(StringUtils.hasText(str), "The argument cannot be blank."); * AssertTools.checkArgument(StringUtils.hasText(str), "The argument cannot be blank.");
* AssertTools.checkState(ArrayUtils.isNotEmpty(result), "The result cannot be empty."); * AssertTools.checkState(ArrayUtils.isNotEmpty(result), "The result cannot be empty.");
* AssertTools.checkCondition(!CollectionUtils.isEmpty(roles), () -> new InvalidInputException("The roles cannot be empty.")); * AssertTools.checkCondition(!CollectionUtils.isEmpty(roles), () -> new InvalidInputException("The roles cannot be empty."));
* </pre> * </pre>
* *
* @author ZhouXY * @author ZhouXY
*/ */
public class AssertTools { public class AssertTools {
// #region - checkArgument
public static <T> void checkArgumentNotNull(T argument) { public static <T> void checkArgumentNotNull(T argument) {
checkCondition(argument != null, () -> new IllegalArgumentException("The argument cannot be null.")); checkCondition(argument != null, () -> new IllegalArgumentException("The argument cannot be null."));
} }
@ -70,6 +72,10 @@ public class AssertTools {
checkCondition(condition, () -> new IllegalArgumentException(String.format(format, args))); checkCondition(condition, () -> new IllegalArgumentException(String.format(format, args)));
} }
// #endregion
// #region - checkState
public static void checkState(boolean condition) { public static void checkState(boolean condition) {
checkCondition(condition, IllegalStateException::new); checkCondition(condition, IllegalStateException::new);
} }
@ -86,6 +92,10 @@ public class AssertTools {
checkCondition(condition, () -> new IllegalStateException(String.format(format, args))); checkCondition(condition, () -> new IllegalStateException(String.format(format, args)));
} }
// #endregion
// #region - checkCondition
public static <T extends Exception> void checkCondition(boolean condition, @Nonnull Supplier<T> e) public static <T extends Exception> void checkCondition(boolean condition, @Nonnull Supplier<T> e)
throws T { throws T {
if (!condition) { if (!condition) {
@ -93,7 +103,13 @@ public class AssertTools {
} }
} }
// #endregion
// #region - private constructor
private AssertTools() { private AssertTools() {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
// #endregion
} }