完善 Assert。

feature/net-util
ZhouXY108 2023-04-21 03:21:21 +08:00
parent b8df9b5f55
commit f4da6b6ca1
1 changed files with 54 additions and 2 deletions

View File

@ -88,7 +88,7 @@ public class Assert {
Assert.isTrue(Objects.nonNull(value), errorMessageTemplate, args);
}
// isEmpty
// isEmpty - Collection
public static <T, E extends Throwable> void isEmpty(@Nullable Collection<T> collection, Supplier<E> e) throws E {
Assert.isTrue((collection == null || collection.isEmpty()), e);
}
@ -101,7 +101,7 @@ public class Assert {
Assert.isTrue((collection == null || collection.isEmpty()), errorMessageTemplate, args);
}
// isNotEmpty
// isNotEmpty - Collection
public static <T, E extends Throwable> void isNotEmpty(@Nullable Collection<T> collection, Supplier<E> e) throws E {
Assert.isFalse((collection == null || collection.isEmpty()), e);
}
@ -114,6 +114,58 @@ public class Assert {
Assert.isFalse((collection == null || collection.isEmpty()), errorMessageTemplate, args);
}
// isEmpty - Array
public static <T, E extends Throwable> void isEmpty(@Nullable T[] arr, Supplier<E> e) throws E {
Assert.isTrue((arr == null || arr.length == 0), e);
}
public static <T> void isEmpty(@Nullable T[] arr, String errorMessage) {
Assert.isTrue((arr == null || arr.length == 0), errorMessage);
}
public static <T> void isEmpty(@Nullable T[] arr, String errorMessageTemplate, Object... args) {
Assert.isTrue((arr == null || arr.length == 0), errorMessageTemplate, args);
}
// isNotEmpty - Collection
public static <T, E extends Throwable> void isNotEmpty(@Nullable T[] arr, Supplier<E> e) throws E {
Assert.isFalse((arr == null || arr.length == 0), e);
}
public static <T> void isNotEmpty(@Nullable T[] arr, String errorMessage) {
Assert.isFalse((arr == null || arr.length == 0), errorMessage);
}
public static <T> void isNotEmpty(@Nullable T[] arr, String errorMessageTemplate, Object... args) {
Assert.isFalse((arr == null || arr.length == 0), errorMessageTemplate, args);
}
// isEmpty - Array
public static <E extends Throwable> void isEmpty(@Nullable String arr, Supplier<E> e) throws E {
Assert.isTrue((arr == null || arr.length() == 0), e);
}
public static void isEmpty(@Nullable String arr, String errorMessage) {
Assert.isTrue((arr == null || arr.length() == 0), errorMessage);
}
public static void isEmpty(@Nullable String arr, String errorMessageTemplate, Object... args) {
Assert.isTrue((arr == null || arr.length() == 0), errorMessageTemplate, args);
}
// isNotEmpty - Collection
public static <E extends Throwable> void isNotEmpty(@Nullable String arr, Supplier<E> e) throws E {
Assert.isFalse((arr == null || arr.length() == 0), e);
}
public static void isNotEmpty(@Nullable String arr, String errorMessage) {
Assert.isFalse((arr == null || arr.length() == 0), errorMessage);
}
public static void isNotEmpty(@Nullable String arr, String errorMessageTemplate, Object... args) {
Assert.isFalse((arr == null || arr.length() == 0), errorMessageTemplate, args);
}
// private consrtuctor
private Assert() {
throw new IllegalStateException("Utility class");