package com.github.wz2cool.dynamic.model;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

import static java.util.stream.Collectors.toList;

/**
 * @author Frank
 **/
public class NormPagingResult<T> {
    /**
     * 是否有上一页
     */
    private boolean hasPreviousPage;
    /**
     * 是否有下一页
     */
    private boolean hasNextPage;
    /**
     * 每页数量
     */
    private int pageSize;
    /**
     * 页码
     */
    private int pageNum;
    /**
     * 总页数
     */
    private int pages;
    /**
     * 总记录数
     */
    private long total;
    /**
     * 结果集
     */
    private List<T> list = new ArrayList<>();


    /**
     * 转换 NormPagingResult 的数据泛型
     *
     * @param mapper 数据类型映射关系
     * @param <O>    目标数据泛型
     * @return 目标数据泛型的 {@link NormPagingResult}
     */
    public <O> NormPagingResult<O> convert(Function<? super T, ? extends O> mapper) {
        List<O> collect = this.getList().stream().map(mapper).collect(toList());
        return copyPageResult(this, collect);
    }

    /**
     * copy page result property and set list is collect
     *
     * @param sourcePageResult 源 {@link NormPagingResult}
     * @param collect          重新设置的数据内容
     * @param <O>              目标数据泛型
     * @return copy 后的目标 {@link NormPagingResult}
     */
    private <O> NormPagingResult<O> copyPageResult(NormPagingResult<T> sourcePageResult, List<O> collect) {
        NormPagingResult<O> objectPageResult = new NormPagingResult<>();
        objectPageResult.setPageNum(sourcePageResult.getPageNum());
        objectPageResult.setPageSize(sourcePageResult.getPageSize());
        objectPageResult.setHasPreviousPage(sourcePageResult.isHasPreviousPage());
        objectPageResult.setHasNextPage(sourcePageResult.isHasNextPage());
        objectPageResult.setPages(sourcePageResult.getPages());
        objectPageResult.setTotal(sourcePageResult.getTotal());
        objectPageResult.setList(collect);
        return objectPageResult;
    }

    public boolean isHasPreviousPage() {
        return hasPreviousPage;
    }

    public void setHasPreviousPage(boolean hasPreviousPage) {
        this.hasPreviousPage = hasPreviousPage;
    }

    public boolean isHasNextPage() {
        return hasNextPage;
    }

    public void setHasNextPage(boolean hasNextPage) {
        this.hasNextPage = hasNextPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List<T> getList() {
        return list == null ? new ArrayList<>() : new ArrayList<>(list);
    }

    public void setList(List<T> list) {
        this.list = list == null ? new ArrayList<>() : new ArrayList<>(list);
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }
}

@@ -989,425 +989,52 @@
     
-return copyPageResult(this, collect);%0A    %7D%0A%0A    /**%0A     * copy page result property and set list is collect%0A     *%0A     * @param sourcePageResult %E6%BA%90 %7B@link NormPagingResult%7D%0A     * @param collect          %E9%87%8D%E6%96%B0%E8%AE%BE%E7%BD%AE%E7%9A%84%E6%95%B0%E6%8D%AE%E5%86%85%E5%AE%B9%0A     * @param %3CO%3E              %E7%9B%AE%E6%A0%87%E6%95%B0%E6%8D%AE%E6%B3%9B%E5%9E%8B%0A     * @return copy %E5%90%8E%E7%9A%84%E7%9B%AE%E6%A0%87 %7B@link NormPagingResult%7D%0A     */%0A    private %3CO%3E NormPagingResult%3CO%3E copyPageResult(NormPagingResult%3CT%3E sourcePageResult, List%3CO%3E 
+((NormPagingResult%3CO%3E)this).setList(
 collect)
  %7B%0A 
@@ -1029,18 +1029,17 @@
 collect)
- %7B
+;
 %0A       
@@ -1043,571 +1043,42 @@
     
-NormPagingResult%3CO%3E objectPageResult = new NormPagingResult%3C%3E();%0A        objectPageResult.setPageNum(sourcePageResult.getPageNum());%0A        objectPageResult.setPageSize(sourcePageResult.getPageSize());%0A        objectPageResult.setHasPreviousPage(sourcePageResult.isHasPreviousPage());%0A        objectPageResult.setHasNextPage(sourcePageResult.isHasNextPage());%0A        objectPageResult.setPages(sourcePageResult.getPages());%0A        objectPageResult.setTotal(sourcePageResult.getTotal());%0A        objectPageResult.setList(collect);%0A        return objectPageResult
+return ((NormPagingResult%3CO%3E)this)
 ;%0A  

修改NormPageResult convert方法的两个泛型对象属性赋值方式