package com.engine.organization.util;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author liang.cheng
 * @Date 2023/9/13 2:46 PM
 * @Description: 通用
 * @Version 1.0
 */
public class OrganizationCommonUtil {


    /**
     * @Description: 集合分割
     * @Author: liang.cheng
     * @Date: 2023/9/13 2:46 PM
     * @param: [list, batchSize]
     * @return: java.util.List<java.util.List<T>>
     */
    public static <T> List<List<T>> splitList(List<T> list, int batchSize) {
        List<List<T>> splittedLists = new ArrayList<>();
        for (int i = 0; i < list.size(); i += batchSize) {
            int endIndex = Math.min(i + batchSize, list.size());
            List<T> subList = list.subList(i, endIndex);
            splittedLists.add(subList);
        }
        return splittedLists;
    }
}
