forked from plusone/plusone-commons
使用 AssertTools 替换 Preconditions。
This commit is contained in:
@@ -20,8 +20,6 @@ import java.util.function.Supplier;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* 枚举工具类
|
||||
*
|
||||
@@ -44,7 +42,7 @@ public final class EnumTools {
|
||||
*/
|
||||
@Deprecated
|
||||
public static <E extends Enum<?>> E valueOf(Class<E> clazz, int ordinal) { // NOSONAR 该方法弃用,但不删掉
|
||||
Preconditions.checkNotNull(clazz, "Clazz must not be null.");
|
||||
AssertTools.checkNotNull(clazz, "Clazz must not be null.");
|
||||
E[] values = clazz.getEnumConstants();
|
||||
AssertTools.checkCondition((ordinal >= 0 && ordinal < values.length),
|
||||
() -> new EnumConstantNotPresentException(clazz, Integer.toString(ordinal)));
|
||||
@@ -102,7 +100,7 @@ public final class EnumTools {
|
||||
@Deprecated
|
||||
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.");
|
||||
AssertTools.checkNotNull(clazz, "Clazz must not be null.");
|
||||
E[] values = clazz.getEnumConstants();
|
||||
return values[0];
|
||||
});
|
||||
@@ -123,8 +121,8 @@ public final class EnumTools {
|
||||
}
|
||||
|
||||
public static <E extends Enum<?>> Integer checkOrdinal(Class<E> clazz, Integer ordinal) {
|
||||
Preconditions.checkNotNull(clazz, "Clazz must not be null.");
|
||||
Preconditions.checkNotNull(ordinal, "Ordinal must not be null.");
|
||||
AssertTools.checkNotNull(clazz, "Clazz must not be null.");
|
||||
AssertTools.checkNotNull(ordinal, "Ordinal must not be null.");
|
||||
E[] values = clazz.getEnumConstants();
|
||||
if (ordinal >= 0 && ordinal < values.length) {
|
||||
return ordinal;
|
||||
|
||||
@@ -24,8 +24,6 @@ import java.util.Objects;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import xyz.zhouxy.plusone.commons.annotation.StaticFactoryMethod;
|
||||
|
||||
/**
|
||||
@@ -43,7 +41,7 @@ public abstract class Enumeration<T extends Enumeration<T>> // NOSONAR 暂不移
|
||||
protected final String name;
|
||||
|
||||
protected Enumeration(final int id, final String name) {
|
||||
Preconditions.checkArgument(StringTools.isNotBlank(name), "Name of enumeration must has text.");
|
||||
AssertTools.checkArgument(StringTools.isNotBlank(name), "Name of enumeration must has text.");
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
@@ -98,7 +96,7 @@ public abstract class Enumeration<T extends Enumeration<T>> // NOSONAR 暂不移
|
||||
}
|
||||
|
||||
public T get(int id) {
|
||||
Preconditions.checkArgument(this.valueMap.containsKey(id), "[%s] 对应的值不存在", id);
|
||||
AssertTools.checkArgument(this.valueMap.containsKey(id), "[%s] 对应的值不存在", id);
|
||||
return this.valueMap.get(id);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user