实现:三个数组中分别取里面的第一个值,第二个值,第三个值重新组成数组

需求: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);
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值