package io.hmit.common.utils;

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

/**
 * @Description :
 * @Author : Shen Yuanfeng
 * @Date : 2021/5/7 9:49
 */
public class SubListForPageUtil {

    public static <T> List<T> getSubList(Map<String, Object> params, List<T> list){
        Integer pageNum = Integer.parseInt(params.get("page").toString());
        Integer pageSize = Integer.parseInt(params.get("limit").toString());
        Integer count = list.size();
        Integer pageNo = (pageNum - 1) * pageSize;
        List<T> list2 ;
        if (pageNo+pageSize > count) {
            if (pageNo > count){
                list2 = new ArrayList<>();
            }else {
                list2 = list.subList(pageNo, count);
            }
        }else {
            list2 = list.subList(pageNo, pageNo+pageSize);
        }
        return list2;
    }

}
