package com.ruoyi.common.utils;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class DataUtil {

    private final static Integer MAX_NUMBER = 1000;


    /**
     * 数据切片
     */
    public static <T> List<List<T>> slice(List<T> list) {

        final Integer limit = countStep(list.size());

        List<List<T>> splitList = Stream.iterate(0, n -> n + 1).limit(limit).parallel().map(a -> list.stream()
                .skip(a * MAX_NUMBER).limit(MAX_NUMBER).parallel().collect(Collectors.toList())).collect(Collectors.toList());

        return splitList;

    }

    private static Integer countStep(Integer size) {
        return (size + MAX_NUMBER - 1) / MAX_NUMBER;
    }
}
