package com.matrix.core.tools;
|
|
import java.util.List;
|
import java.util.function.Function;
|
|
public class ParamCheckUtil {
|
|
/**
|
* 校验列表参数不能为空
|
*
|
* @param args
|
*/
|
public static void requireNonNulls(Object... args) {
|
if (args == null || args.length < 0) {
|
throw new NullPointerException("参数校验列表为空");
|
}
|
for (int i = 0; i < args.length; i++) {
|
if (args[i] == null) {
|
throw new NullPointerException(String.format("参数校验列表第%s个参数为空", i + 1));
|
}
|
}
|
}
|
|
/**
|
* 校验集合中的参数不能为空
|
* requireListElementNonNull(objects, Arrays.asList(OrderItemDto::getCount, OrderItemDto::getGoodsId));
|
* @param
|
*/
|
public static <T> void requireListElementNonNull(List<T> list, List<Function<? super T, ? extends Object>> getterFunctions) {
|
|
requireNonNulls(list,getterFunctions);
|
|
for (int i = 0; i < list.size(); i++) {
|
for (int j = 0; j < getterFunctions.size(); j++) {
|
if(getterFunctions.get(j).apply(list.get(i))==null){
|
throw new NullPointerException(String.format("集合中第%s个对象第%s参数为空",i+1,j+1));
|
}
|
}
|
|
}
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
}
|
|
}
|