From 47eb91d01571b4403be45b2c057e99edbbed10ce Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Wed, 19 Jul 2023 00:44:42 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20PreconditionsExt=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=B3=A8=E9=87=8A=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/xyz/zhouxy/plusone/commons/util/EnumUtil.java | 2 +- .../zhouxy/plusone/commons/util/PreconditionsExt.java | 9 ++++++++- 2 files changed, 9 insertions(+), 2 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 1d3091f..1d250df 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/EnumUtil.java @@ -46,7 +46,7 @@ public final class EnumUtil { public static > E valueOf(Class clazz, int ordinal) { Preconditions.checkNotNull(clazz, "Clazz must not be null."); E[] values = clazz.getEnumConstants(); - PreconditionsExt.isTrue((ordinal >= 0 && ordinal < values.length), + PreconditionsExt.check((ordinal >= 0 && ordinal < values.length), () -> new EnumConstantNotPresentException(clazz, Integer.toString(ordinal))); return values[ordinal]; } diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java b/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java index 6726233..909dfbb 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/PreconditionsExt.java @@ -18,9 +18,16 @@ package xyz.zhouxy.plusone.commons.util; import java.util.function.Supplier; +/** + * Guava Preconditions 的扩展。 + * + * @author ZhouXY + * + * @see com.google.common.base.Preconditions + */ public class PreconditionsExt { - public static void isTrue(boolean condition, Supplier e) throws E { + public static void check(boolean condition, Supplier e) throws E { if (!condition) { throw e.get(); }