修改方法名。

dev
ZhouXY108 2024-10-12 00:21:19 +08:00
parent 6eb5ada623
commit 979ff1760f
3 changed files with 21 additions and 14 deletions

View File

@ -179,7 +179,7 @@ public class ArrayTools {
* @throws IllegalArgumentException * @throws IllegalArgumentException
*/ */
public static <T> boolean isAllElementsNotNull(@Nonnull final T[] arr) { public static <T> boolean isAllElementsNotNull(@Nonnull final T[] arr) {
AssertTools.checkParameter(arr != null, "The array cannot be null."); AssertTools.checkArgument(arr != null, "The array cannot be null.");
for (T element : arr) { for (T element : arr) {
if (element == null) { if (element == null) {
return false; return false;

View File

@ -29,27 +29,34 @@ import javax.annotation.Nonnull;
*/ */
public class AssertTools { public class AssertTools {
public static <T> void checkParameterNotNull(String paramName, T value) { public static <T> void checkArgumentNotNull(T obj) {
checkCondition(value != null, checkCondition(obj != null, () -> new IllegalArgumentException("The argument cannot be null."));
() -> new IllegalArgumentException(String.format("The parameter \"%s\" cannot be null.", paramName)));
} }
public static <T> void checkParameterNotNull(T obj, String errMsg) { public static <T> void checkArgumentNotNull(T obj, String errMsg) {
checkCondition(obj != null, () -> new IllegalArgumentException(errMsg)); checkCondition(obj != null, () -> new IllegalArgumentException(errMsg));
} }
public static <T> void checkParameterNotNull(T obj, String format, Object... args) { public static <T> void checkArgumentNotNull(T obj, String format, Object... args) {
checkCondition(obj != null, () -> new IllegalArgumentException(String.format(format, args))); checkCondition(obj != null, () -> new IllegalArgumentException(String.format(format, args)));
} }
public static void checkParameter(boolean condition, String errMsg) { public static void checkArgument(boolean condition) {
checkCondition(condition, IllegalArgumentException::new);
}
public static void checkArgument(boolean condition, String errMsg) {
checkCondition(condition, () -> new IllegalArgumentException(errMsg)); checkCondition(condition, () -> new IllegalArgumentException(errMsg));
} }
public static void checkParameter(boolean condition, String format, Object... args) { public static void checkArgument(boolean condition, String format, Object... args) {
checkCondition(condition, () -> new IllegalArgumentException(String.format(format, args))); checkCondition(condition, () -> new IllegalArgumentException(String.format(format, args)));
} }
public static void checkState(boolean condition) {
checkCondition(condition, IllegalStateException::new);
}
public static void checkState(boolean condition, String errMsg) { public static void checkState(boolean condition, String errMsg) {
checkCondition(condition, () -> new IllegalStateException(errMsg)); checkCondition(condition, () -> new IllegalStateException(errMsg));
} }

View File

@ -51,7 +51,7 @@ public class BigDecimals {
* 使{@link RoundingMode#HALF_UP} * 使{@link RoundingMode#HALF_UP}
*/ */
public static String toPlainString(@Nonnull BigDecimal value) { public static String toPlainString(@Nonnull BigDecimal value) {
AssertTools.checkParameterNotNull("value", value); AssertTools.checkArgumentNotNull(value, "The argument \"value\" cannot be null.");
return toPlainStringInternal(value, DEFAULT_STR_SCALE, DEFAULT_STR_ROUNDING_MODE); return toPlainStringInternal(value, DEFAULT_STR_SCALE, DEFAULT_STR_ROUNDING_MODE);
} }
@ -59,7 +59,7 @@ public class BigDecimals {
* 使{@link RoundingMode#HALF_UP} * 使{@link RoundingMode#HALF_UP}
*/ */
public static String toPlainString(@Nonnull BigDecimal value, int scale) { public static String toPlainString(@Nonnull BigDecimal value, int scale) {
AssertTools.checkParameterNotNull("value", value); AssertTools.checkArgumentNotNull(value, "The argument \"value\" cannot be null.");
return toPlainStringInternal(value, scale, DEFAULT_STR_ROUNDING_MODE); return toPlainStringInternal(value, scale, DEFAULT_STR_ROUNDING_MODE);
} }
@ -67,8 +67,8 @@ public class BigDecimals {
* 使 {@link RoundingMode} * 使 {@link RoundingMode}
*/ */
public static String toPlainString(@Nonnull BigDecimal value, @Nonnull RoundingMode roundingMode) { public static String toPlainString(@Nonnull BigDecimal value, @Nonnull RoundingMode roundingMode) {
AssertTools.checkParameterNotNull("value", value); AssertTools.checkArgumentNotNull(value, "The argument \"value\" cannot be null.");
AssertTools.checkParameterNotNull("rounding mode", roundingMode); AssertTools.checkArgumentNotNull(roundingMode, "The argument \"rounding mode\" cannot be null.");
return toPlainStringInternal(value, DEFAULT_STR_SCALE, roundingMode); return toPlainStringInternal(value, DEFAULT_STR_SCALE, roundingMode);
} }
@ -77,8 +77,8 @@ public class BigDecimals {
*/ */
public static String toPlainString(@Nonnull BigDecimal value, public static String toPlainString(@Nonnull BigDecimal value,
int scale, @Nonnull RoundingMode roundingMode) { int scale, @Nonnull RoundingMode roundingMode) {
AssertTools.checkParameterNotNull("value", value); AssertTools.checkArgumentNotNull(value, "The argument \"value\" cannot be null.");
AssertTools.checkParameterNotNull("rounding mode", roundingMode); AssertTools.checkArgumentNotNull(roundingMode, "The argument \"rounding mode\" cannot be null.");
return toPlainStringInternal(value, scale, roundingMode); return toPlainStringInternal(value, scale, roundingMode);
} }