From ebcd02144c1978c94d83c7f2398dfe034e82a908 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 25 Jun 2023 11:17:46 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20EnumUtil=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/commons/util/EnumUtil.java | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java index d4709b5..3b92e83 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java @@ -130,18 +130,41 @@ public final class EnumUtil { throw new EnumConstantNotPresentException(clazz, Integer.toString(ordinal)); } - @Deprecated + /** + * 校验枚举的 ordinal。 + * + * @param 枚举类型 + * @param clazz 枚举类型 + * @param ordinal The ordinal + * @return The ordinal + */ + @Nullable public static > Integer checkOrdinalNullable(Class clazz, @Nullable Integer ordinal) { return checkOrdinalOrDefault(clazz, ordinal, null); } - @Deprecated + /** + * 校验枚举的 ordinal,如果 ordinal 为 {@code null},则返回 {@code 0}。 + * + * @param 枚举类型 + * @param clazz 枚举类型 + * @param ordinal The ordinal + * @return The ordinal + */ + @Nullable public static > Integer checkOrdinalOrDefault(Class clazz, @Nullable Integer ordinal) { return checkOrdinalOrDefault(clazz, ordinal, 0); } + /** + * 校验枚举的 ordinal,如果 ordinal 为 {@code null},则返回 {@code defaultValue}。 + * + * @param 枚举类型 + * @param clazz 枚举类型 + * @param ordinal The ordinal + * @return The ordinal + */ @Nullable - @Deprecated public static > Integer checkOrdinalOrDefault( Class clazz, @Nullable Integer ordinal,