需求:a,b,c三个list中分别又有三个list,然后分别取a,b,c中的第一个list值,第二个list值,第三个list分别组成新的list(a,b,c中的值可能为空,最大为3个list)
思路:先算出a,b,c三个当中最大的长度,然后for循环依次取a,b,c的第一个值放到list中,第二个值放list中,第三个值放list中。注:要考虑到a,b,c中值不全的情况
实现
SimpleProInstrumentVO类
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class SimpleProInstrumentVO {
List<Student> listDay = new ArrayList<>();
List<Student> listWeek = new ArrayList<>();
List<Student> listMon = new ArrayList<>();
}
实现部分
SimpleProInstrumentVO simpleProInstrumentVO = opSupportService.getSupportInsts(user.getBrokerId(), index, typeEnum, expiry);
if(simpleProInstrumentVO == null || "".equals(simpleProInstrumentVO)){
return null;
}
List<List<Student>> instrumentListsDay = new ArrayList<>();
List<List<Student>> instrumentListsWeek = new ArrayList<>();
List<List<Student>> instrumentListsMon = new ArrayList<>();
instrumentListsDay.add(simpleProInstrumentVO.getListDay());
instrumentListsWeek.add(simpleProInstrumentVO.getListWeek());
instrumentListsMon.add(simpleProInstrumentVO.getListMon());
if (CollectionUtils.isEmpty(instrumentListsDay)) {
return null;
}
//添加
int daySize = instrumentListsDay != null && !"".equals(instrumentListsDay) ? instrumentListsDay.get(0).size() : 0;
int weekSize = instrumentListsWeek != null && !"".equals(instrumentListsWeek) ? instrumentListsWeek.get(0).size() : 0;
int monSize = instrumentListsMon != null && !"".equals(instrumentListsMon) ? instrumentListsMon.get(0).size() : 0;
int maxNumber = getMax(daySize,weekSize,monSize);
for(int i=0;i<maxNumber;i++){
List<SimpleProductsVO> simpleProductsVOList = new ArrayList<>();
Student instDay = simpleProInstrumentVO.getListDay() != null && simpleProInstrumentVO.getListDay().size() != 0 && daySize > i ? simpleProInstrumentVO.getListDay().get(i) : null;
Student instWeek = simpleProInstrumentVO.getListWeek() != null && simpleProInstrumentVO.getListWeek().size() != 0 && weekSize > i ? simpleProInstrumentVO.getListWeek().get(i) : null;
Student instMon = simpleProInstrumentVO.getListMon() != null && simpleProInstrumentVO.getListMon().size() != 0 && monSize > i ? simpleProInstrumentVO.getListMon().get(i) : null;
SimpleProductsVO productsVODay = getProductsVO(instDay);
if(productsVODay != null && !"".equals(productsVODay)){
productsVODay.setType("S");
simpleProductsVOList.add(productsVODay);
}
SimpleProductsVO productsVOWeek = getProductsVO(instWeek);
if(productsVOWeek != null && !"".equals(productsVOWeek)){
productsVOWeek.setType("M");
simpleProductsVOList.add(productsVOWeek);
}
SimpleProductsVO productsVOMon = getProductsVO(instMon);
if(productsVOMon != null && !"".equals(productsVOMon)){
productsVOMon.setType("L");
simpleProductsVOList.add(productsVOMon);
}
lists.add(simpleProductsVOList);
}
return lists;
}
public int getMax(int daySize,int weekSize,int monSize)
{
return daySize>weekSize?(daySize>monSize?daySize:monSize):(weekSize>monSize?weekSize:monSize);
}