修改方法名。
parent
6eb5ada623
commit
979ff1760f
|
@ -179,7 +179,7 @@ public class ArrayTools {
|
|||
* @throws IllegalArgumentException 当参数为空时抛出
|
||||
*/
|
||||
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) {
|
||||
if (element == null) {
|
||||
return false;
|
||||
|
|
|
@ -29,27 +29,34 @@ import javax.annotation.Nonnull;
|
|||
*/
|
||||
public class AssertTools {
|
||||
|
||||
public static <T> void checkParameterNotNull(String paramName, T value) {
|
||||
checkCondition(value != null,
|
||||
() -> new IllegalArgumentException(String.format("The parameter \"%s\" cannot be null.", paramName)));
|
||||
public static <T> void checkArgumentNotNull(T obj) {
|
||||
checkCondition(obj != null, () -> new IllegalArgumentException("The argument cannot be null."));
|
||||
}
|
||||
|
||||
public static <T> void checkParameterNotNull(T obj, String errMsg) {
|
||||
public static <T> void checkArgumentNotNull(T obj, String 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)));
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
|
||||
public static void checkState(boolean condition) {
|
||||
checkCondition(condition, IllegalStateException::new);
|
||||
}
|
||||
|
||||
public static void checkState(boolean condition, String errMsg) {
|
||||
checkCondition(condition, () -> new IllegalStateException(errMsg));
|
||||
}
|
||||
|
|
|
@ -51,7 +51,7 @@ public class BigDecimals {
|
|||
* 使用四舍五入({@link RoundingMode#HALF_UP}),保留两位小数,转为字符串。
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class BigDecimals {
|
|||
* 使用四舍五入({@link RoundingMode#HALF_UP}),保留指定位的小数,转为字符串。
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -67,8 +67,8 @@ public class BigDecimals {
|
|||
* 使用指定 {@link RoundingMode},保留两位小数,转为字符串。
|
||||
*/
|
||||
public static String toPlainString(@Nonnull BigDecimal value, @Nonnull RoundingMode roundingMode) {
|
||||
AssertTools.checkParameterNotNull("value", value);
|
||||
AssertTools.checkParameterNotNull("rounding mode", roundingMode);
|
||||
AssertTools.checkArgumentNotNull(value, "The argument \"value\" cannot be null.");
|
||||
AssertTools.checkArgumentNotNull(roundingMode, "The argument \"rounding mode\" cannot be null.");
|
||||
return toPlainStringInternal(value, DEFAULT_STR_SCALE, roundingMode);
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ public class BigDecimals {
|
|||
*/
|
||||
public static String toPlainString(@Nonnull BigDecimal value,
|
||||
int scale, @Nonnull RoundingMode roundingMode) {
|
||||
AssertTools.checkParameterNotNull("value", value);
|
||||
AssertTools.checkParameterNotNull("rounding mode", roundingMode);
|
||||
AssertTools.checkArgumentNotNull(value, "The argument \"value\" cannot be null.");
|
||||
AssertTools.checkArgumentNotNull(roundingMode, "The argument \"rounding mode\" cannot be null.");
|
||||
return toPlainStringInternal(value, scale, roundingMode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue