forked from plusone/plusone-commons
修改 PreconditionsExt,添加注释。
parent
2086f22e63
commit
47eb91d015
|
@ -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];
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue