cursor中测试大模型代码优化能力

 现在测试对单个文件类的代码进行优化,优化的代码是:

/**
 * @author :jiaotao
 * @description:数据接口
 * @date :Created in 2023/6/29 11:44
 */
@Service
@Slf4j
public class DataServiceImpl_a_copy {

    @DubboReference(timeout = 300000)
    private IndexService indexService;
    @DubboReference(timeout = 30000)
    private SyncHolidayService syncHolidayService;

    @Autowired
    private DataCataLogService dataCataLogService;



    @Value("${index.relation.calculate.path}")
    private String indexCalcPath;

    public List<IndexValueVO> getIndexData(List<IndexCalDTO> requests) {
        try {
            String publishEndTime = null;
            if (!org.springframework.util.CollectionUtils.isEmpty(requests)) {
                IndexCalDTO indexCalDTO = requests.get(0);
                publishEndTime = Boolean.TRUE.equals(indexCalDTO.getIsCut()) && StringUtils.isNotEmpty(indexCalDTO.getEndTime()) && StringUtils.isEmpty(indexCalDTO.getPublishEndTime()) ? indexCalDTO.getEndTime() : indexCalDTO.getPublishEndTime();
            }
            requests.stream().forEach(e -> {
                if (null != e.getSeqPeriodType()) {
                    List<IndexDTO> indexRequestList = e.getIndexRequestList();
                    if (!org.springframework.util.CollectionUtils.isEmpty(indexRequestList)) {
                        IndexDTO indexRequest = indexRequestList.get(0);
                        Integer seqPeriod = null;
                        switch (indexRequest.getFrequencyName()) {
                            case "日度":
                                if (e.getSeqPeriodType() == 1) {
                                    seqPeriod = 1;
                                } else if (e.getSeqPeriodType() == 2) {
                                    seqPeriod = 7;
                                } else if (e.getSeqPeriodType() == 3) {
                                    seqPeriod = 28;
                                }
                                break;
                            case "周度":
                                if (e.getSeqPeriodType() == 2) {
                                    seqPeriod = 1;
                                } else if (e.getSeqPeriodType() == 3) {
                                    seqPeriod = 4;
                                }
                                break;
                            case "月度":
                                if (e.getSeqPeriodType() == 3) {
                                    seqPeriod = 1;
                                }
                                break;
                            default:
                                break;
                        }
                        e.setSeqPeriod(seqPeriod);
                    }
                }
                if (StringUtils.isNotEmpty(e.getDataDate())) {
                    e.setEndTime(e.getDataDate());
                }
            });
            Vector<IndexValueVO> responses = new Vector<>();
            CountDownLatch buildMapCountDownLatch = new CountDownLatch(2);
            Map<String, List<IndexDataVO>> indexCodeDataMapType1 = new HashMap<>();
            Map<String, List<IndexDataVO>> indexCodeDataMapType2 = new HashMap<>();
            Map<String, String> unitMap = new HashMap<>();
            //同个指标可能存在两种分时数据,分时数据分开存储
            Map<String, List<IndexDataVO>> dataMapType1 = new HashMap<>();
            Map<String, List<IndexDataVO>> dataMapType2 = new HashMap<>();
            //根据分时数据类型进行分组
            Map<Integer, List<IndexCalDTO>> valueTypeMap = requests.stream().map(e -> {
                if (e.getValueType() == null || e.getValueType() == 0) {
                    e.setValueType(2);
                }
                return e;
            }).collect(Collectors.groupingBy(IndexCalDTO::getValueType));
            Set<Integer> valueTypeSet = valueTypeMap.keySet();
            String finalPublishEndTime = publishEndTime;
            new Thread(() -> {
                try {
                    //获取指标单位
                    Map<String, String> frequencyMap = requests.stream().map(x -> x.getDateIndexRequestList()).flatMap(o -> o.stream()).filter(indexRequest -> indexRequest.getFrequencyName() != null)
                            .collect(Collectors.toMap(IndexDTO::getIndexCode, IndexDTO::getFrequencyName, (k1, k2) -> k1));
                    unitMap.putAll(frequencyMap);
                    valueTypeSet.forEach(valueType -> {
                        // 计算原生指标数据
                        List<String> deriveIndexCodeList = valueTypeMap.get(valueType).stream().map(x -> x.getDateIndexRequestList()).flatMap(o -> o.stream())
                                .filter(indexRequest -> DeriveEnum.DERIVE.getCode().equals(indexRequest.getIsDerive()))
                                .map(IndexDTO::getIndexCode).distinct().collect(Collectors.toList());
                        List<String> indexCodeList = valueTypeMap.get(valueType).stream().map(x -> x.getDateIndexRequestList()).flatMap(o -> o.stream())
                                .filter(indexRequest -> DeriveEnum.NOT_DERIVE.getCode().equals(indexRequest.getIsDerive()))
                                .map(IndexDTO::getIndexCode).distinct().collect(Collectors.toList());
                        Map<String, Integer> decimalPlaces = valueTypeMap.get(valueType).stream().map(x -> x.getDateIndexRequestList()).flatMap(o -> o.stream()).filter(indexRequest -> indexRequest.getDecimalPlaces() != null)
                                .collect(Collectors.toMap(IndexDTO::getIndexCode, IndexDTO::getDecimalPlaces, (k1, k2) -> k1));

                        Map<String, List<IndexDataVO>> resultMap = new HashMap<>();
                        long startTime = System.currentTimeMillis();
                        if(CollectionUtils.isNotEmpty(indexCodeList)){
                            List<List<String>> splitindexCodeListBySize = splitStringListBySize(indexCodeList, 50);
                            for (List<String> list:splitindexCodeListBySize) {
                                QueryIndexDTO queryRequest = new QueryIndexDTO();
                                queryRequest.setCompleteData(false);
                                queryRequest.setSortByDate(SORT);
                                queryRequest.setIndexCodes(new ArrayList<>(list));
                                queryRequest.setValueType(valueType);
                                queryRequest.setDecimalPlaces(decimalPlaces);
                                queryRequest.setPublishEndTime(finalPublishEndTime);
                                CommonResponse<Map<String, List<IndexDataVO>>> indexCodeListDataResponse = indexService.getIndexDataBatch(queryRequest);
                                if (!indexCodeListDataResponse.isSuccess()) {
                                    throw new DataBaseException(DataBaseExceptionEnum.FAIL);
                                }
                                Map<String, List<IndexDataVO>> data = indexCodeListDataResponse.getData();
                                resultMap.putAll(data);
                            }
                        }
                        if(CollectionUtils.isNotEmpty(deriveIndexCodeList)){
                            List<List<String>> splitindexCodeListBySize = splitStringListBySize(deriveIndexCodeList, 50);
                            for (List<String> list:splitindexCodeListBySize) {
                                QueryIndexDTO queryRequest = new QueryIndexDTO();
                                queryRequest.setCompleteData(false);
                                queryRequest.setSortByDate(SORT);
                                queryRequest.setDeriveIndexes(new ArrayList<>(list));
                                queryRequest.setValueType(valueType);
                                queryRequest.setDecimalPlaces(decimalPlaces);
                                queryRequest.setPublishEndTime(finalPublishEndTime);
                                CommonResponse<Map<String, List<IndexDataVO>>> indexCodeListDataResponse = indexService.getIndexDataBatch(queryRequest);
                                if (!indexCodeListDataResponse.isSuccess()) {
                                    throw new DataBaseException(DataBaseExceptionEnum.FAIL);
                                }
                                Map<String, List<IndexDataVO>> data = indexCodeListDataResponse.getData();
                                resultMap.putAll(data);
                            }
                        }
                        log.info("---------原生指标查询耗时-----------" + (System.currentTimeMillis() - startTime));



                        if (valueType == 1) {
                            indexCodeDataMapType1.putAll(resultMap);
                        } else {
                            indexCodeDataMapType2.putAll(resultMap);
                        }

                    });
                    buildMapCountDownLatch.countDown();
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    buildMapCountDownLatch.countDown();
                }
            }).start();
            Map<IndexCalDTO, Set<String>> indexFormulaMap = new HashMap<>();
            String finalPublishEndTime1 = publishEndTime;
            new Thread(() -> {
                try {
                    valueTypeSet.forEach(valueType -> {
                        Set<String> indexFormulaList = new HashSet<>();
                        Map<String, Integer> decimalPlaces = new HashMap<>();
                        Map<String, Integer> isPercentageChangeMap = new HashMap<>();
                        valueTypeMap.get(valueType).forEach(request -> {
                            if (request.getDeriveOption() != null) {
                                buildIndexRequestListFrequencyData(request);
                                List<IndexCalVO> indexCalVO = dataCataLogService.getIndexCalFormula(request);
                                Set<String> set = indexCalVO.stream().map(e -> {
                                    isPercentageChangeMap.put(e.getIndexCode(), e.getIsPercentageChange());
                                    if (e.getDecimalPlaces() != null) {
                                        decimalPlaces.put(e.getIndexCode(), e.getDecimalPlaces());
                                    }
                                    if ((QOQ_DATA_CHANGE.matcher(e.getIndexCode()).matches() || YOY_DATA_CHANGE.matcher(e.getIndexCode()).matches())) {
                                        decimalPlaces.put(e.getIndexCode(), 2);
                                    }
                                    return e.getIndexCode();
                                }).collect(Collectors.toSet());

                                indexFormulaMap.put(request, set);
                                indexFormulaList.addAll(set);
                            }
                        });
                        List<List<String>> indexFormulaLists = Lists.partition(new ArrayList<>(indexFormulaList), 2);
                        CountDownLatch indexFormulaCountDownLatch = new CountDownLatch(indexFormulaLists.size());
                        indexFormulaLists.forEach(y -> {
                            ThreadPoolSingletonUtils.getThreadPoolExecutor().execute(() -> {
                                try {
                                    QueryIndexDTO indexRequest = new QueryIndexDTO();
                                    indexRequest.setSortByDate(SORT);
                                    indexRequest.setDeriveIndexes(new ArrayList<>(y));
                                    indexRequest.setValueType(valueType);
                                    indexRequest.setDecimalPlaces(decimalPlaces);
                                    indexRequest.setPublishEndTime(finalPublishEndTime1);
                                    long startTime1 = System.currentTimeMillis();
                                    CommonResponse<Map<String, List<IndexDataVO>>> indexFormulaDataResponse = indexService.getIndexDataBatch(indexRequest);
                                    log.info("---------指标衍生计算查询耗时-----------" + (System.currentTimeMillis() - startTime1));

                                    if (!indexFormulaDataResponse.isSuccess()) {
                                        throw new DataBaseException(DataBaseExceptionEnum.FAIL);
                                    }
                                    Map<String, List<IndexDataVO>> formulaDataResponseData = indexFormulaDataResponse.getData();
                                    Set<String> keySet = formulaDataResponseData.keySet();
                                    if (!org.springframework.util.CollectionUtils.isEmpty(keySet)) {
                                        for (String key : keySet) {
                                            //是否是同环比百分比
                                            Integer isPercentageChange = isPercentageChangeMap.get(key);
                                            if (null != isPercentageChange) {
                                                List<IndexDataVO> indexDataRespons = formulaDataResponseData.get(key);
                                                indexDataRespons.stream().forEach(e -> {
                                                    if (StringUtils.isNotEmpty(e.getDataValue())) {
                                                        if (1 == isPercentageChange) {
                                                            e.setDataValue(e.getDataValue() + "%");
                                                        } else if (2 == isPercentageChange) {
                                                            if (Double.valueOf(e.getDataValue()) == 0) {
                                                                e.setDataValue("0");
                                                            } else {
                                                                DecimalFormat decimalFormat = new DecimalFormat("0.000000");
                                                                String format = decimalFormat.format(Double.valueOf(e.getDataValue()));
                                                                e.setDataValue(format);
                                                            }
                                                        }
                                                    }
                                                });

                                            }


                                        }
                                    }
                                    if (valueType == 1) {
                                        dataMapType1.putAll(formulaDataResponseData);
                                    } else {
                                        dataMapType2.putAll(formulaDataResponseData);
                                    }
                                    indexFormulaCountDownLatch.countDown();
                                } catch (Exception e) {
                                    log.error(e.getMessage(), e);
                                    indexFormulaCountDownLatch.countDown();
                                }
                            });
                        });
                        try {
                            indexFormulaCountDownLatch.await(2, TimeUnit.MINUTES);
                        } catch (InterruptedException e) {
                            log.error(e.getMessage(), e);
                        }
                    });
                    buildMapCountDownLatch.countDown();
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                    buildMapCountDownLatch.countDown();
                }
            }).start();
            buildMapCountDownLatch.await(2, TimeUnit.MINUTES);
            CountDownLatch countDownLatch = new CountDownLatch(requests.size());
            requests.forEach(request -> {
                ThreadPoolSingletonUtils.getThreadPoolExecutor().execute(() -> {
                    try {
                        if (request.getRows() == null || request.getPosition() == null) {
                            countDownLatch.countDown();
                            return;
                        }
                        Set<String> codeList = request.getDateIndexRequestList().stream().filter(y -> DeriveEnum.DERIVE.getCode().equals(y.getIsDerive())
                                || DeriveEnum.NOT_DERIVE.getCode().equals(y.getIsDerive()))
                                .map(IndexDTO::getIndexCode).collect(Collectors.toSet());
                        //原生指标日期并集
                        List<String> dateAllList = Lists.newArrayList();
                        //原生指标日期
                        List<String> dateList = Lists.newArrayList();
                        //原生指标数据
                        List<IndexDataVO> indexCodeDataResponses = Lists.newArrayList();
                        codeList.stream().forEach(indexCode -> {
                            List<IndexDataVO> dateIndexDataRespons = request.getValueType() == 1 ? indexCodeDataMapType1.get(indexCode) : indexCodeDataMapType2.get(indexCode);
                            if(StringUtils.isNotEmpty(request.getTimeType())){
                                CommonResponse<Map<String, String>> timeInterval = getTimeInterval(-1L, request.getTimeType());
                                Map<String, String> timeIntervalDataMap = timeInterval.getData();
                                String startTime = timeIntervalDataMap.get(START_TIME);
                                String endTime = timeIntervalDataMap.get(END_TIME);
                                dateIndexDataRespons = dateIndexDataRespons.stream().filter(e -> e.getDataDate().compareTo(startTime) >= 0 && e.getDataDate().compareTo(endTime) <= 0).collect(Collectors.toList());
                            }
                            String unitName = unitMap.get(indexCode);
                            if (CollectionUtils.isNotEmpty(dateIndexDataRespons)) {
                                List<String> indexCodeDateList;
                                //判断是否存在数据截断情况
                                if (request.getIsCut() != null && request.getIsCut() && StringUtils.isNotEmpty(request.getEndTime())) {
                                    String frequencyEndDate = DateUtil.getFrequencyEndDate(unitName, request.getEndTime());
                                    indexCodeDateList = dateIndexDataRespons.stream().filter(x -> x.getDataDate().compareTo(frequencyEndDate) <= 0)
                                            .map(IndexDataVO::getDataDate).collect(Collectors.toList());
                                } else {
                                    if (StringUtils.isNotEmpty(request.getEndTime())) {
                                        indexCodeDateList = dateIndexDataRespons.stream().filter(x -> x.getDataDate().compareTo(request.getEndTime()) <= 0).map(IndexDataVO::getDataDate).collect(Collectors.toList());
                                    } else {
                                        indexCodeDateList = dateIndexDataRespons.stream().map(IndexDataVO::getDataDate).collect(Collectors.toList());
                                    }
                                }
                                //本身过滤
                                List<String> dateIndexList = Lists.newArrayList();
                                if (indexCode.equals(request.getIndexRequestList().get(0).getIndexCode())) {
                                    dateIndexList = indexCodeDateList.stream().distinct().sorted().collect(Collectors.toList());
                                    if (request.getDeriveOption() == null) {
                                        if ((request.getIsCut() == null || !request.getIsCut()) && StringUtils.isNotEmpty(request.getEndTime())) {
                                            indexCodeDataResponses.addAll(dateIndexDataRespons.stream().filter(x -> x.getDataDate().compareTo(request.getEndTime()) <= 0).collect(Collectors.toList()));
                                        } else {
                                            indexCodeDataResponses.addAll(dateIndexDataRespons);
                                        }
                                    }
                                }
                                dateList.addAll(dateIndexList);
                                dateAllList.addAll(indexCodeDateList);
                            }
                        });
                        List<String> dateUnionList = dateAllList.stream().distinct().sorted().collect(Collectors.toList());
                        List<String> finalDateList = dateList;
                        //计算公式
                        if (request.getDeriveOption() != null) {
                            Set<String> indexFormulas = indexFormulaMap.get(request);
                            List<IndexValueVO> indexFormulaDataList = new ArrayList<>();
                            if (!org.springframework.util.CollectionUtils.isEmpty(indexFormulas)) {
                                indexFormulaDataList = indexFormulas.stream().map(indexFormula -> {
                                    IndexValueVO indexValueVO = new IndexValueVO();
                                    List<IndexDataVO> indexDataRespons = request.getValueType() == 1 ? dataMapType1.get(indexFormula) : dataMapType2.get(indexFormula);
                                    indexValueVO.setIndexCode(indexFormula);
                                    indexValueVO.setIsDerive(DeriveEnum.DERIVE.getCode());
                                    indexValueVO.setPosition(request.getPosition());
                                    //判断是否存在数据截断情况
                                    if (request.getIsCut() != null && request.getIsCut() && StringUtils.isNotEmpty(request.getEndTime())) {
                                        String frequencyEndDate = DateUtil.getFrequencyEndDate(request.getIndexRequestList().get(0).getFrequencyName(), request.getEndTime());
                                        indexDataRespons = indexDataRespons.stream().filter(x -> x.getDataDate().compareTo(frequencyEndDate) <= 0).collect(Collectors.toList());
                                    } else {
                                        if (StringUtils.isNotEmpty(request.getEndTime())) {
                                            indexDataRespons = indexDataRespons.stream().filter(x -> x.getDataDate().compareTo(request.getEndTime()) <= 0).collect(Collectors.toList());
                                        }
                                    }
                                    Map<String, String> dataValueMap = indexDataRespons.stream().collect(Collectors.toMap(IndexDataVO::getDataDate, IndexDataVO::getDataValue));
                                    List<IndexValueVO.IndexValue> indexValues;
                                    if (CollectionUtils.isEmpty(dateUnionList)) {
                                        indexValues = indexDataRespons.stream().map(indexDataResponse -> {
                                            IndexValueVO.IndexValue indexValue = new IndexValueVO.IndexValue();
                                            indexValue.setDataValue(indexDataResponse.getDataValue());
                                            indexValue.setDate(indexDataResponse.getDataDate());
                                            indexValue.setJoint(false);
                                            return indexValue;
                                        }).sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList());
                                    } else {
                                        indexValues = dateUnionList.stream().map(data -> {
                                            IndexValueVO.IndexValue indexValue = new IndexValueVO.IndexValue();
                                            indexValue.setDataValue(dataValueMap.get(data));
                                            indexValue.setDate(data);
                                            //判断原始日期是否是否包含此日期,包含为原始数据的值,不包含为拼接的值
                                            boolean joint = finalDateList.contains(data);
                                            //是否为拼接的值。true表示为拼接的值
                                            indexValue.setJoint(joint ? false : true);
                                            return indexValue;
                                        }).sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList());
                                    }
                                    //最新数据过滤掉拼接的日期数据
                                    if (request.getTableType() != null && request.getTableType() == 0) {
                                        indexValueVO.setIndexValues(indexValues.stream().filter(e -> !e.getJoint()).collect(Collectors.toList()));
                                    } else {
                                        indexValueVO.setIndexValues(indexValues);
                                    }
                                    buildTableData(indexValueVO, dataValueMap, request);
                                    return indexValueVO;
                                }).collect(Collectors.toList());
                            }
                            responses.addAll(indexFormulaDataList);
                        } else {
                            IndexValueVO indexValueVO = new IndexValueVO();
                            indexValueVO.setIndexCode(request.getIndexRequestList().get(0).getIndexCode());
                            indexValueVO.setIsDerive(DeriveEnum.NOT_DERIVE.getCode());
                            indexValueVO.setPosition(request.getPosition());
                            Map<String, String> dataValueMap = indexCodeDataResponses.stream().filter(e -> StringUtils.isNotEmpty(e.getDataValue())).collect(Collectors.toMap(IndexDataVO::getDataDate, IndexDataVO::getDataValue));
                            List<IndexValueVO.IndexValue> indexValues = dateUnionList.stream().map(data -> {
                                IndexValueVO.IndexValue indexValue = new IndexValueVO.IndexValue();
                                indexValue.setDataValue(dataValueMap.get(data));
                                indexValue.setDate(data);
                                //判断原始日期是否是否包含此日期,包含为原始数据的值,不包含为拼接的值
                                boolean joint = finalDateList.contains(data);
                                //是否为拼接的值。true表示为拼接的值
                                indexValue.setJoint(joint ? false : true);
                                return indexValue;
                            }).sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList());
                            //最新数据过滤掉拼接的日期数据
                            if (request.getTableType() != null && request.getTableType() == 0) {
                                indexValueVO.setIndexValues(indexValues.stream().filter(e -> !e.getJoint()).collect(Collectors.toList()));
                            } else {
                                indexValueVO.setIndexValues(indexValues);
                            }
                            buildTableData(indexValueVO, dataValueMap, request);
                            responses.add(indexValueVO);
                        }
                        countDownLatch.countDown();
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                        countDownLatch.countDown();
                    }
                });
            });
            countDownLatch.await(2, TimeUnit.MINUTES);

            if (!org.springframework.util.CollectionUtils.isEmpty(responses)) {
                IndexCalDTO indexCalDTO = requests.get(0);
                String dataDate = indexCalDTO.getDataDate();
            }
            return responses;
        } catch (Exception e) {
            log.error("error occur when getIndexData paran={},msg={}", JSON.toJSONString(requests), e.getMessage());
            throw new DataBaseException(DataBaseExceptionEnum.FAIL);
        }
    }


    /**
     * 将list按照size进行分割
     *
     * @param list
     * @param size
     * @return
     */
    private List<List<String>> splitStringListBySize(List<String> list, int size) {
        //获取到list的长度
        int length = list.size();
        int num = (length + size - 1) / size;
        List<List<String>> newList = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            int fromIndex = i * size;
            int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
            newList.add(list.subList(fromIndex, toIndex));
        }
        return newList;
    }





    public static void main(String[] args) {
        List<String> thisWeekList = getThisMonthList("2023-12-11");
        System.out.println("--");
    }
    private static List<String> getThisMonthList(String dateString){
        List<String> dateList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Date date = null;
        try {
            date = sdf.parse(dateString);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        calendar.setTime(date);

        String[] dates = new String[calendar.getActualMaximum(Calendar.DAY_OF_MONTH)];
        for (int i = 0; i < dates.length; i++) {
            calendar.set(Calendar.DAY_OF_MONTH, i + 1);
            dates[i] = sdf.format(calendar.getTime());
        }

        // 输出结果
        for (String thisDate : dates) {
            dateList.add(thisDate);
        }
        return dateList;
    }

    /**
     * 频度字段赋值
     *
     * @param request
     */
    private void buildIndexRequestListFrequencyData(IndexCalDTO request) {
        request.getIndexRequestList().forEach(indexRequest -> {
            DervierFreEnum enumByZhName = DervierFreEnum.getEnumByZhName(indexRequest.getFrequencyName());
            indexRequest.setFrequency(enumByZhName.getCode());
        });
    }

    public void buildTableData(IndexValueVO indexValueVO, Map<String, String> dataValueMap, IndexCalDTO request) {
        String frequency = request.getIndexRequestList().get(0).getFrequencyName();
        if (!org.springframework.util.CollectionUtils.isEmpty(indexValueVO.getIndexValues())) {
            indexValueVO.getIndexValues().sort(Comparator.comparing(IndexValueVO.IndexValue::getDate).reversed());
            //若存在日期选择,替换存在日期选择的值
            if (request.getDateType() != null && request.getDateType() != 0) {
                //日期选择为固定日期
                if (request.getDateType() == 5 && StringUtils.isNotEmpty(request.getDateValue())) {
                    request.setTableType(0);
                    //最新数据是按数据往下排
                    if (request.getTableType() == 0) {
                        List<IndexValueVO.IndexValue> contrastIndexValues = indexValueVO.getIndexValues().stream().filter(indexValue -> indexValue.getDate().compareTo(request.getDateValue()) <= 0).limit(request.getRows()).collect(Collectors.toList());
                        List<IndexValueVO.IndexValue> indexValueList = indexValueVO.getIndexValues().stream().limit(request.getRows()).collect(Collectors.toList());
                        if (CollectionUtil.isNotEmpty(contrastIndexValues)) {
                            for (int i = 0; i < indexValueList.size(); i++) {
                                indexValueList.get(i).setDataValue(CollectionUtil.isNotEmpty(contrastIndexValues) && i < contrastIndexValues.size() ? contrastIndexValues.get(i).getDataValue() : null);
                                indexValueList.get(i).setDate(CollectionUtil.isNotEmpty(contrastIndexValues) && i < contrastIndexValues.size() ? contrastIndexValues.get(i).getDate() : null);
                            }
                        } else {
                            indexValueList = indexValueList.stream().map(indexValue -> {
                                indexValue.setDataValue(null);
                                return indexValue;
                            }).collect(Collectors.toList());
                        }
                        indexValueVO.setIndexValues(indexValueList.stream().filter(t->t.getDate() != null).sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList()));
                    } else {
                        //取各个频度的对应的日期
                        String preDate = DateUtil.getFrequencyEndDate(frequency, request.getDateValue());
                        List<IndexValueVO.IndexValue> indexValueList = indexValueVO.getIndexValues().stream().limit(request.getRows()).collect(Collectors.toList());
                        if (CollectionUtil.isNotEmpty(indexValueList)) {
                            for (int i = 0; i < indexValueList.size(); i++) {
                                String dateTime = preDate;
                                Map<String, String> dateMap = new HashMap<>();
                                dateMap.put(DATE, dateTime);
                                switch (frequency) {
                                    case "日度":
                                        /*dateTime = DateUtil.getPrevDate(preDate,-i);*/
                                        int j = 0;
                                        if (j < i) {
                                            dateTime = syncHolidayService.previousWorkDay(dateTime);
                                            dateMap.put(DATE, dateTime);
                                            j++;
                                            getDayDate(j, i, dateMap);
                                        }
                                        break;
                                    case "周度":
                                        dateTime = DateUtil.getPrevWeekDate(preDate, -i);
                                        dateMap.put(DATE, dateTime);
                                        break;
                                    case "旬度":
                                        dateTime = DateUtil.getPrevDecadalDate(preDate, i);
                                        dateMap.put(DATE, dateTime);
                                        break;
                                    case "月度":
                                        dateTime = DateUtil.getPrevMonthDate(preDate, -i);
                                        dateMap.put(DATE, dateTime);
                                        break;
                                    case "季度":
                                        dateTime = DateUtil.getPrevMonthDate(preDate, -i * 3);
                                        dateMap.put(DATE, dateTime);
                                        break;
                                    case "半年度":
                                        dateTime = DateUtil.getPrevMonthDate(preDate, -i * 6);
                                        dateMap.put(DATE, dateTime);
                                        break;
                                    case "年度":
                                        dateTime = DateUtil.getPrevYearDate(preDate, -i);
                                        dateMap.put(DATE, dateTime);
                                        break;
                                    default:
                                        break;
                                }
                                indexValueList.get(i).setDataValue(dataValueMap.get(dateMap.get(DATE)));
                            }
                            indexValueVO.setIndexValues(indexValueList.stream().sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList()));
                        }
                    }
                }
                else if(null!=request.getDateType()&&(request.getDateType()==6||request.getDateType()==7||request.getDateType()==8)){
                    List<IndexValueVO.IndexValue> indexValues = indexValueVO.getIndexValues();
                    if(StringUtils.isNotEmpty(request.getBeginTime())){
                        indexValues = indexValues.stream().filter(e -> e.getDate().compareTo(request.getBeginTime()) >= 0 ).collect(Collectors.toList());
                    }
                    if(StringUtils.isNotEmpty(request.getEndTime())){
                        indexValues = indexValues.stream().filter(e ->  e.getDate().compareTo(request.getEndTime()) <= 0).collect(Collectors.toList());
                    }
                    if(CollectionUtils.isEmpty(indexValues)){
                        indexValueVO.setIndexValues(indexValues);
                        return;
                    }
                    if(request.getDateType()==6){
                        Optional<String> maxOptional = indexValues.stream().filter(e -> StringUtils.isNotEmpty(e.getDataValue())).map(e -> e.getDataValue()).max(Comparator.comparingDouble(Double::valueOf));
                        if(maxOptional.isPresent()){
                            String maxValue = maxOptional.get();
                            indexValues = indexValues.stream().filter(e -> maxValue.equals(e.getDataValue())).collect(Collectors.toList());
                        }
                    }else if(request.getDateType()==7){
                        Optional<String> minOptional = indexValues.stream().filter(e -> StringUtils.isNotEmpty(e.getDataValue())).map(e -> e.getDataValue()).min(Comparator.comparingDouble(Double::valueOf));
                        if(minOptional.isPresent()){
                            String minValue = minOptional.get();
                            indexValues = indexValues.stream().filter(e -> minValue.equals(e.getDataValue())).collect(Collectors.toList());
                        }
                    }else if(request.getDateType()==8){
                        List<IndexValueVO.IndexValue> collect = indexValues.stream().filter(e -> StringUtils.isNotBlank(e.getDataValue())).collect(Collectors.toList());
                        if(CollUtil.isNotEmpty(collect)){
                            IndexValueVO.IndexValue indexValue = collect.get(0);
                            indexValues = Collections.singletonList(indexValue);
                        }else {
                            IndexValueVO.IndexValue indexValue = indexValues.get(0);
                            indexValues = Collections.singletonList(indexValue);
                        }

                    }
                    indexValueVO.setIndexValues(indexValues);
                }
                else {
                    indexValueVO.setIndexValues(indexValueVO.getIndexValues().stream().limit(request.getRows()).map(indexValue -> {
                        String preDate = getFrequencyLastDate(frequency, indexValue.getDate(), request.getDateType());
                        if("日度".equals(frequency)&&request.getDateType()==1){
                            Optional<String> maxOptional = dataValueMap.keySet().stream().filter(e -> e.compareTo(indexValue.getDate()) < 0).max(String::compareTo);
                            if(maxOptional.isPresent()){
                                preDate = maxOptional.get();
                            }
                        }
                        indexValue.setDataValue(dataValueMap.get(preDate));
                        indexValue.setDate(preDate);
                        return indexValue;
                    }).sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList()));
                }
            } else {
                List<IndexValueVO.IndexValue> collect = indexValueVO.getIndexValues().stream().limit(request.getRows()).sorted(Comparator.comparing(IndexValueVO.IndexValue::getDate)).collect(Collectors.toList());
                indexValueVO.setIndexValues(collect);
            }
        }
    }

    /**
     * 获取每个频度日期选择的日期
     *
     * @param: unit 频度
     * @param: dateStr 日期
     * @param: dateType 日期选择类型  1上期值(日、周、旬、月、季、半年、年度)、2上周同期值(日度)、3上月同期(日、周度)、4去年同期(日、周、旬、月、季、半年年度)
     * @return: java.lang.String
     **/
    private String getFrequencyLastDate(String frequency, String dateStr, Integer dateType) {
        //判断日期
        String thisDate = dateStr;
        switch (dateType) {
            case 1:
                if (frequency.equals("日度")) {
                    //thisDate = DateUtil.getPrevDate(dateStr,1);
                    thisDate = syncHolidayService.previousWorkDay(dateStr);
                } else if (frequency.equals("周度")) {
                    thisDate = DateUtil.getPrevWeekDate(dateStr, -1);
                } else if (frequency.equals("旬度")) {
                    int nowDay = Integer.parseInt(dateStr.substring(8, 10));
                    if (nowDay == 31) {
                        thisDate = DateUtil.getPrevDate(dateStr, 11);
                    } else if (nowDay == 28) {
                        thisDate = DateUtil.getPrevDate(dateStr, 8);
                    } else {
                        thisDate = DateUtil.getPrevDate(dateStr, 10);
                    }
                } else if (frequency.equals("月度")) {
                    thisDate = DateUtil.getPrevMonthDate(dateStr, -1);
                } else if (frequency.equals("季度")) {
                    thisDate = DateUtil.getPrevMonthDate(dateStr, -3);
                } else if (frequency.equals("半年度")) {
                    thisDate = DateUtil.getPrevMonthDate(dateStr, -6);
                } else {
                    thisDate = DateUtil.getPrevYearDate(dateStr, -1);
                }
                break;
            case 2:
                thisDate = DateUtil.getPrevWeekDate(dateStr, -1);
                break;
            case 3:
                if (frequency.equals("日度")) {
                    thisDate = DateUtil.getPrevDate(dateStr, 30);
                } else {
                    thisDate = DateUtil.getPrevWeekDate(dateStr, -4);
                }
                break;
            case 4:
                if (frequency.equals("周度")) {
                    thisDate = DateUtil.getPrevWeekDate(dateStr, -52);
                } else {
                    thisDate = DateUtil.getPrevYearDate(dateStr, -1);
                }
                break;
            default:
                break;
        }
        return thisDate;
    }

    public void getDayDate(Integer j, Integer i, Map<String, String> dateMap) {
        if (j < i) {
            String dateTime = syncHolidayService.previousWorkDay(dateMap.get(DATE));
            dateMap.put(DATE, dateTime);
            j++;
            getDayDate(j, i, dateMap);
        }
    }


    public List<IndexInfoVO> getIndexInfoNew(IndexDataQueryDTO request) {

        List<IndexInfoVO> allList = new ArrayList<>();
        // 衍生指标信息以前端为准
        if (Objects.nonNull(request.getIndexData())) {
            request.getIndexData().forEach(i -> {
                if (i.getIndexCode().indexOf("$") > -1) {
                    allList.add(ConvertUtils.converEntity(i, IndexInfoVO.class));
                }
            });
        }
        // 指标转换,将衍生指标转换为原生指标
        List<String> deriveIndexCode = request.getIndexCodes().stream().filter(i -> i.indexOf("$") > -1).collect(Collectors.toList());
        // 拆解衍生指标为原生指标并获取指标信息
        List<String> indexCodes = new ArrayList<>();
        deriveIndexCode.forEach(d -> {
            try {
                List<String> temp = DerivationBusinessMethod.getIndexCodes(d);

                temp.forEach(t -> {
                    if (!indexCodes.contains(t)) {
                        indexCodes.add(t);
                    }
                });
            } catch (Exception ex) {
                log.error("指标拆解失败:", ex);
                throw new DataBaseException(DataBaseExceptionEnum.INDEX_DATA_DERIVE_SPLIT_ERROR);
            }
        });
        indexCodes.addAll(request.getIndexCodes());
        // 获取指标信息
        CommonResponse<List<IndexInfoVO>> indexData = indexService.getIndexInfoBatch(indexCodes);

        //转换并组装数据
        Map<String, IndexInfoVO> indexPoMap = indexData.getData().stream().collect(Collectors.toMap(IndexInfoVO::getIndexCode, Function.identity()));
        Map<String, IndexInfoVO> allResponse = allList.stream().collect(Collectors.toMap(IndexInfoVO::getIndexCode, Function.identity()));
        request.getIndexCodes().forEach(code -> {
            IndexInfoVO response = ConvertUtils.converEntity(indexPoMap.get(code), IndexInfoVO.class);

            if (allResponse.containsKey(code)) {
//                allList.remove(allResponse.get(code));
            }
            if (code.indexOf("$") > -1) {
                try {
                    // 拆分衍生指标
                    List<String> temp = DerivationBusinessMethod.getIndexCodes(code);

                    response.setPrimoridialIndex(Lists.newArrayList());
                    temp.forEach(t -> {
                        if (indexPoMap.containsKey(t)) {
                            response.getPrimoridialIndex().add(ConvertUtils.converEntity(indexPoMap.get(t), IndexInfoVO.class));
                        }
                    });
                } catch (Exception ex) {
                }
                if (response != null) {
                    allList.add(response);
                }
            } else {
                if (indexPoMap.containsKey(code)) {
                    allList.add(response);
                }
            }
        });

        return allList;
    }

    public CommonResponse<Map<String, String>> getTimeInterval(Long timeCount, String timeType) {
        if (timeType.equals(RequestFrequencyEnum.OBSERVED.getDesc())) {
            Map<String, String> map = new HashMap<>();
            map.put(RequestFrequencyEnum.OBSERVED.getDesc(), timeCount.toString());
            return CommonResponse.buildRespose4Success(map);
        }
        LocalDate nowTime = LocalDate.now();
        Map<String, String> map = new HashMap<>();
        buildDateMap(timeType, map, nowTime, timeCount);
        return CommonResponse.buildRespose4Success(map);
    }

    private void buildDateMap(String timeType, Map<String, String> map, LocalDate nowTime, Long timeCount) {
        if(StringUtils.isNotEmpty(timeType)){
            timeType = timeType.replace("最近", "近");
        }
        if (timeType.equals(RequestFrequencyEnum.DAY.getDesc())) {
            map.put(START_TIME, nowTime.plusDays(-timeCount).toString());
        } else if (timeType.equals(RequestFrequencyEnum.WEEK.getDesc())) {
            map.put(START_TIME, nowTime.plusWeeks(-timeCount).toString());
        } else if (timeType.equals(RequestFrequencyEnum.MONTH.getDesc())) {
            map.put(START_TIME, nowTime.plusMonths(-timeCount).toString());
        } else if (timeType.equals(RequestFrequencyEnum.YEAR.getDesc())) {
            map.put(START_TIME, nowTime.plusYears(-timeCount).toString());
        } else if (timeType.equals(RequestFrequencyEnum.HALF_YEAR.getDesc())) {
            map.put(START_TIME, nowTime.plusMonths(-6).toString());
        } else if (timeType.equals(RequestFrequencyEnum.ONE_YEAR.getDesc())) {
            map.put(START_TIME, nowTime.plusYears(-1).toString());
        } else if (timeType.equals(RequestFrequencyEnum.THREE_YEAR.getDesc())) {
            map.put(START_TIME, nowTime.plusYears(-3).toString());
        } else if (timeType.equals(RequestFrequencyEnum.FIVE_YEAR.getDesc())) {
            map.put(START_TIME, nowTime.plusYears(-5).toString());
        }else if(timeType.equals(RequestFrequencyEnum.ONE_SEASON.getDesc())){
            map.put(START_TIME, nowTime.plusMonths(-3).toString());
        }else if(timeType.equals(RequestFrequencyEnum.ONE_MONTH.getDesc())){
            map.put(START_TIME, nowTime.plusMonths(-1).toString());
        }else if(timeType.equals(RequestFrequencyEnum.ONE_DEKAD.getDesc())){
            map.put(START_TIME, nowTime.plusDays(-10).toString());
        } else if(timeType.equals(RequestFrequencyEnum.ONE_WEEK.getDesc())){
            map.put(START_TIME, nowTime.plusWeeks(-1).plusDays(1).toString());
        }
        map.put(END_TIME, nowTime.toString());
    }
       /**
     * 获取日期集合
     *
     * @param map
     * @param sortByDate
     * @return
     */
    public List<String> getFormatDayList(Map<String, List<DataDateVO>> map, Integer sortByDate) {
        List<List<DataDateVO>> collect = map.values().stream().collect(Collectors.toList());
        List<DataDateVO> dataList = Lists.newArrayList();
        collect.stream().forEach(mapList -> {
            dataList.addAll(mapList);
        });
        List<DataDateVO> dateVOList = dataList.stream().collect(
                Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
                        Comparator.comparing(DataDateVO::getName)
                )), ArrayList::new));
        dateVOList.stream().forEach(dataDateVO -> {
            if (StringUtils.equals(DateUtil.SPRING_FESTIVAL, dataDateVO.getName())) {
                dataDateVO.setSort(Constant.ZERO_LONG);
            }
            if (dataDateVO.getName().contains(FORWARD)) {
                dataDateVO.setSort(-Long.valueOf(dataDateVO.getName().substring(1, dataDateVO.getName().length() - 1)));
            }
            if (dataDateVO.getName().contains(BEHIND)) {
                dataDateVO.setSort(Long.valueOf(dataDateVO.getName().substring(1, dataDateVO.getName().length() - 1)));
            }
        });

        if (SORT.equals(sortByDate)) {
            Collections.sort(dateVOList, Comparator.comparing(DataDateVO::getSort).reversed());
        } else {
            Collections.sort(dateVOList, Comparator.comparing(DataDateVO::getSort));
        }
        return dateVOList.stream().map(DataDateVO::getName).collect(Collectors.toList());
    }

    public static void isTrue(final boolean expression, final String message) {
        if (!expression) {
            throw new CommonException("500", message);
        }
    }
}

由上所示,这个代码有很多问题

现在用各大模型对这段代码进行一键优化

1、claude-3.5-sonnat大模型(cursor agent模式)

优化后的代码为: 

package com.mysteel.standard.database.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSON;
import com.google.common.collect.Lists;
import com.mysteel.standard.common.enums.exception.DataBaseExceptionEnum;
import com.mysteel.standard.common.exception.database.DataBaseException;
import com.mysteel.standard.common.model.response.CommonResponse;
import com.mysteel.standard.common.util.*;
import com.mysteel.standard.data.model.dto.QueryIndexDTO;
import com.mysteel.standard.data.model.vo.IndexDataVO;
import com.mysteel.standard.data.model.vo.IndexInfoVO;
import com.mysteel.standard.data.provider.IndexService;
import com.mysteel.standard.data.provider.SyncHolidayService;
import com.mysteel.standard.database.constants.Constant;
import com.mysteel.standard.database.enums.DeriveEnum;
import com.mysteel.standard.database.enums.RequestFrequencyEnum;
import com.mysteel.standard.database.exception.CommonException;
import com.mysteel.standard.database.model.dto.*;
import com.mysteel.standard.database.model.vo.*;
import com.mysteel.standard.database.service.DataCataLogService;
import com.mysteel.standard.database.util.*;
import com.mysteel.standard.unifyformular.business.DerivationBusinessMethod;
import com.mysteel.standard.unifyformular.enums.DervierFreEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.*;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import static com.mysteel.standard.database.constants.Constant.*;
import java.util.regex.Pattern;

/**
 * @author :jiaotao
 * @description:数据接口
 * @date :Created in 2023/6/29 11:44
 */
@Service
@Slf4j
public class DataServiceImpl_claude {

    private static final int BATCH_SIZE = 50;
    private static final int TIMEOUT_MINUTES = 2;
    private static final String DATE_PATTERN = "yyyy-MM-dd";
    private static final DecimalFormat DECIMAL_FORMAT = new DecimalFormat("0.000000");
    private static final String DATE = "date";
    private static final String START_TIME = "startTime";
    private static final String END_TIME = "endTime";
    private static final Pattern QOQ_DATA_CHANGE = Pattern.compile(".*_QOQ$");
    private static final Pattern YOY_DATA_CHANGE = Pattern.compile(".*_YOY$");

    @DubboReference(timeout = 300000)
    private IndexService indexService;
    @DubboReference(timeout = 30000)
    private SyncHolidayService syncHolidayService;

    @Autowired
    private DataCataLogService dataCataLogService;

    @Value("${index.relation.calculate.path}")
    private String indexCalcPath;

    /**
     * 获取指标数据
     */
    public List<IndexValueVO> getIndexData(List<IndexCalDTO> requests) {
        try {
            if (CollectionUtils.isEmpty(requests)) {
                return Collections.emptyList();
            }

            String publishEndTime = getPublishEndTime(requests.get(0));
            
            // 处理请求参数
            processRequests(requests, publishEndTime);

            // 并行处理数据
            Vector<IndexValueVO> responses = new Vector<>();
            CountDownLatch buildMapCountDownLatch = new CountDownLatch(2);
            
            Map<String, List<IndexDataVO>> indexCodeDataMapType1 = new HashMap<>();
            Map<String, List<IndexDataVO>> indexCodeDataMapType2 = new HashMap<>();
            Map<String, String> unitMap = new HashMap<>();
            Map<String, List<IndexDataVO>> dataMapType1 = new HashMap<>();
            Map<String, List<IndexDataVO>> dataMapType2 = new HashMap<>();

            // 按值类型分组处理
            Map<Integer, List<IndexCalDTO>> valueTypeMap = groupRequestsByValueType(requests);
            Set<Integer> valueTypeSet = valueTypeMap.keySet();

            // 启动并行处理线程
            startProcessingThreads(valueTypeSet, valueTypeMap, publishEndTime, buildMapCountDownLatch,
                    indexCodeDataMapType1, indexCodeDataMapType2, dataMapType1, dataMapType2, unitMap);

            // 等待处理完成
            if (!buildMapCountDownLatch.await(TIMEOUT_MINUTES, TimeUnit.MINUTES)) {
                throw new DataBaseException(DataBaseExceptionEnum.FAIL);
            }

            // 处理响应数据
            processResponses(requests, responses, indexCodeDataMapType1, indexCodeDataMapType2,
                    dataMapType1, dataMapType2, unitMap);

            return responses;

        } catch (Exception e) {
            log.error("获取指标数据失败, 参数={}, 错误={}", JSON.toJSONString(requests), e.getMessage());
            throw new DataBaseException(DataBaseExceptionEnum.FAIL);
        }
    }

    /**
     * 获取发布结束时间
     */
    private String getPublishEndTime(IndexCalDTO request) {
        return Boolean.TRUE.equals(request.getIsCut()) && 
               StringUtils.isNotEmpty(request.getEndTime()) && 
               StringUtils.isEmpty(request.getPublishEndTime()) ? 
               request.getEndTime() : request.getPublishEndTime();
    }

    /**
     * 处理请求参数
     */
    private void processRequests(List<IndexCalDTO> requests, String publishEndTime) {
        requests.forEach(request -> {
            processSeqPeriodType(request);
            if (StringUtils.isNotEmpty(request.getDataDate())) {
                request.setEndTime(request.getDataDate());
            }
        });
    }

    /**
     * 处理序列周期类型
     */
    private void processSeqPeriodType(IndexCalDTO request) {
        if (request.getSeqPeriodType() == null) {
            return;
        }

        List<IndexDTO> indexRequestList = request.getIndexRequestList();
        if (CollectionUtils.isEmpty(indexRequestList)) {
            return;
        }

        IndexDTO indexRequest = indexRequestList.get(0);
        Integer seqPeriod = calculateSeqPeriod(indexRequest.getFrequencyName(), request.getSeqPeriodType());
        request.setSeqPeriod(seqPeriod);
    }

    /**
     * 计算序列周期
     */
    private Integer calculateSeqPeriod(String frequencyName, Integer seqPeriodType) {
        switch (frequencyName) {
            case "日度":
                return calculateDailySeqPeriod(seqPeriodType);
            case "周度":
                return calculateWeeklySeqPeriod(seqPeriodType);
            case "月度":
                return seqPeriodType == 3 ? 1 : null;
            default:
                return null;
        }
    }

    private Integer calculateDailySeqPeriod(Integer type) {
        switch (type) {
            case 1: return 1;
            case 2: return 7;
            case 3: return 28;
            default: return null;
        }
    }

    private Integer calculateWeeklySeqPeriod(Integer type) {
        switch (type) {
            case 2: return 1;
            case 3: return 4;
            default: return null;
        }
    }

    /**
     * 将list按照size进行分割
     *
     * @param list
     * @param size
     * @return
     */
    private List<List<String>> splitStringListBySize(List<String> list, int size) {
        //获取到list的长度
        int length = list.size();
        int num = (length + size - 1) / size;
        List<List<String>> newList = new ArrayList<>(num);
        for (int i = 0; i < num; i++) {
            int fromIndex = i * size;
            int toIndex = (i + 1) * size < length ? (i + 1) * size : length;
            newList.add(list.subList(fromIndex, toIndex));
        }
        return newList;
    }

    public static void main(String[] args) {
        List<String> thisWeekList = 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值