修改 PreconditionsExt,添加注释。

feature/net-util
ZhouXY108 2023-07-19 00:44:42 +08:00
parent 2086f22e63
commit 47eb91d015
2 changed files with 9 additions and 2 deletions

View File

@ -46,7 +46,7 @@ public final class EnumUtil {
public static <E extends Enum<?>> E valueOf(Class<E> 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];
}

View File

@ -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 <E extends Throwable> void isTrue(boolean condition, Supplier<E> e) throws E {
public static <E extends Throwable> void check(boolean condition, Supplier<E> e) throws E {
if (!condition) {
throw e.get();
}