添加注释

dev
ZhouXY108 2024-08-23 18:31:39 +08:00
parent 91c30412de
commit 527b0f0980
4 changed files with 144 additions and 6 deletions

12
pom.xml
View File

@ -53,6 +53,18 @@
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>5.9.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>

View File

@ -6,6 +6,16 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.annotation.Documented;
/**
* UnsupportedOperation
*
* <p> {@link UnsupportedOperationException}
*
* @author zhouxy
* @version 1.0
* @since 1.0
* @see UnsupportedOperationException
*/
@Documented
@Target({ ElementType.CONSTRUCTOR, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)

View File

@ -30,68 +30,147 @@ public class ArrayTools {
// isNullOrEmpty
/**
*
*
* @param arr {@code null}
* @param <T>
* @return {@code null} 0 {@code true} {@code false}
*/
public static <T> boolean isNullOrEmpty(@Nullable T[] arr) {
return arr == null || arr.length == 0;
}
// isNullOrEmpty - float
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNullOrEmpty(@Nullable float[] arr) {
return arr == null || arr.length == 0;
}
// isNullOrEmpty - double
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNullOrEmpty(@Nullable double[] arr) {
return arr == null || arr.length == 0;
}
// isNullOrEmpty - byte
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNullOrEmpty(@Nullable byte[] arr) {
return arr == null || arr.length == 0;
}
// isNullOrEmpty - long
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNullOrEmpty(@Nullable long[] arr) {
return arr == null || arr.length == 0;
}
// isNullOrEmpty - int
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNullOrEmpty(@Nullable int[] arr) {
return arr == null || arr.length == 0;
}
// isNotEmpty
/**
*
*
* @param arr {@code null}
* @param <T>
* @return {@code null} 0 {@code true} {@code false}
*/
public static <T> boolean isNotEmpty(@Nullable T[] arr) {
return arr != null && arr.length > 0;
}
// isNotEmpty - float
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNotEmpty(@Nullable float[] arr) {
return arr != null && arr.length > 0;
}
// isNotEmpty - double
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNotEmpty(@Nullable double[] arr) {
return arr != null && arr.length > 0;
}
// isNotEmpty - byte
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNotEmpty(@Nullable byte[] arr) {
return arr != null && arr.length > 0;
}
// isNotEmpty - long
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNotEmpty(@Nullable long[] arr) {
return arr != null && arr.length > 0;
}
// isNotEmpty - int
/**
*
*
* @param arr {@code null}
* @return {@code null} 0 {@code true} {@code false}
*/
public static boolean isNotEmpty(@Nullable int[] arr) {
return arr != null && arr.length > 0;
}
// concat
/**
*
*
* @param arrays {@code null}
* @return
*/
public static float[] concatFloatArray(@Nullable Collection<float[]> arrays) {
if (arrays == null || arrays.isEmpty()) {
return new float[0];
@ -106,6 +185,12 @@ public class ArrayTools {
return result;
}
/**
*
*
* @param arrays {@code null}
* @return
*/
public static double[] concatDoubleArray(@Nullable Collection<double[]> arrays) {
if (arrays == null || arrays.isEmpty()) {
return new double[0];
@ -120,6 +205,12 @@ public class ArrayTools {
return result;
}
/**
*
*
* @param arrays {@code null}
* @return
*/
public static byte[] concatByteArray(@Nullable Collection<byte[]> arrays) {
if (arrays == null || arrays.isEmpty()) {
return new byte[0];
@ -134,6 +225,12 @@ public class ArrayTools {
return result;
}
/**
*
*
* @param arrays {@code null}
* @return
*/
public static long[] concatLongArray(@Nullable Collection<long[]> arrays) {
if (arrays == null || arrays.isEmpty()) {
return new long[0];
@ -148,6 +245,12 @@ public class ArrayTools {
return result;
}
/**
*
*
* @param arrays {@code null}
* @return
*/
public static int[] concatIntArray(@Nullable Collection<int[]> arrays) {
if (arrays == null || arrays.isEmpty()) {
return new int[0];
@ -162,15 +265,28 @@ public class ArrayTools {
return result;
}
/**
*
*
* @param arrays
* @param <T>
* @return
*/
public static <T> List<T> concatToList(@Nullable Collection<T[]> arrays) {
// 如果输入的集合是否为空,则直接返回一个空列表
if (arrays == null || arrays.isEmpty()) {
return Collections.emptyList();
}
// 计算所有数组的总长度,用于初始化列表的容量
final int length = arrays.stream().mapToInt(a -> a.length).sum();
final List<T> result = new ArrayList<>(length);
for (T[] arr : arrays) {
Collections.addAll(result, arr);
}
// 返回连接后的列表
return result;
}

View File

@ -43,7 +43,7 @@ public final class EnumTools {
* @deprecated 使 ordinal
*/
@Deprecated
public static <E extends Enum<?>> E valueOf(Class<E> clazz, int ordinal) {
public static <E extends Enum<?>> E valueOf(Class<E> clazz, int ordinal) { // NOSONAR 该方法弃用,但不删掉
Preconditions.checkNotNull(clazz, "Clazz must not be null.");
E[] values = clazz.getEnumConstants();
PreconditionsExt.check((ordinal >= 0 && ordinal < values.length),
@ -62,7 +62,7 @@ public final class EnumTools {
* @deprecated 使 ordinal
*/
@Deprecated
public static <E extends Enum<?>> E valueOf(Class<E> clazz, @Nullable Integer ordinal, E defaultValue) {
public static <E extends Enum<?>> E valueOf(Class<E> clazz, @Nullable Integer ordinal, E defaultValue) { // NOSONAR 该方法弃用,但不删掉
if (null == ordinal) {
return defaultValue;
}
@ -80,7 +80,7 @@ public final class EnumTools {
* @deprecated 使 ordinal
*/
@Deprecated
public static <E extends Enum<?>> E getValueOrDefault(
public static <E extends Enum<?>> E getValueOrDefault( // NOSONAR 该方法弃用,但不删掉
Class<E> clazz,
@Nullable Integer ordinal,
Supplier<E> defaultValue) {
@ -100,7 +100,7 @@ public final class EnumTools {
* @deprecated 使 ordinal
*/
@Deprecated
public static <E extends Enum<?>> E getValueOrDefault(Class<E> clazz, @Nullable Integer ordinal) {
public static <E extends Enum<?>> E getValueOrDefault(Class<E> clazz, @Nullable Integer ordinal) { // NOSONAR 该方法弃用,但不删掉
return getValueOrDefault(clazz, ordinal, () -> {
Preconditions.checkNotNull(clazz, "Clazz must not be null.");
E[] values = clazz.getEnumConstants();
@ -118,7 +118,7 @@ public final class EnumTools {
* @deprecated 使 ordinal
*/
@Deprecated
public static <E extends Enum<?>> E getValueNullable(Class<E> clazz, @Nullable Integer ordinal) {
public static <E extends Enum<?>> E getValueNullable(Class<E> clazz, @Nullable Integer ordinal) { // NOSONAR 该方法弃用,但不删掉
return valueOf(clazz, ordinal, null);
}