forked from plusone/plusone-commons
添加 checkAllNotNull 方法
This commit is contained in:
@@ -18,9 +18,11 @@ package xyz.zhouxy.plusone.commons.util;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
/**
|
||||
* Guava Preconditions 的扩展。
|
||||
*
|
||||
*
|
||||
* @author ZhouXY
|
||||
*
|
||||
* @see com.google.common.base.Preconditions
|
||||
@@ -33,6 +35,21 @@ public class PreconditionsExt {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, E extends Throwable> void checkAllNotNull(Iterable<T> values) throws E {
|
||||
Preconditions.checkNotNull(values);
|
||||
for (T item : values) {
|
||||
Preconditions.checkNotNull(item);
|
||||
}
|
||||
}
|
||||
|
||||
@SafeVarargs
|
||||
public static <T, E extends Throwable> void checkAllNotNull(T... values) throws E {
|
||||
Preconditions.checkNotNull(values);
|
||||
for (T item : values) {
|
||||
Preconditions.checkNotNull(item);
|
||||
}
|
||||
}
|
||||
|
||||
private PreconditionsExt() {
|
||||
throw new IllegalStateException("Utility class");
|
||||
}
|
||||
|
Reference in New Issue
Block a user