com.haoxuer.discover.user.utils.ConverResourceUtils Maven / Gradle / Ivy
package com.haoxuer.discover.user.utils;
import com.haoxuer.discover.rest.base.ResponseList;
import com.haoxuer.discover.rest.base.ResponsePage;
import com.haoxuer.discover.data.core.Pagination;
import com.haoxuer.discover.data.page.Page;
import com.haoxuer.discover.data.rest.core.Conver;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* Created by ada on 2017/5/23.
*/
public class ConverResourceUtils {
public ConverResourceUtils() {
}
public static void cover(ResponsePage result, Page pager) {
result.setNo(pager.getPageNumber());
result.setSize(pager.getPageSize());
result.setTotal((int) pager.getTotal());
result.setTotalPage(pager.getTotalPages());
}
public static void cover(ResponsePage result, Pagination pager) {
result.setNo(pager.getPageNo());
result.setSize(pager.getPageSize());
result.setTotal((int) pager.getTotalCount());
result.setTotalPage(pager.getTotalPage());
}
public static ResponsePage coverPage(ResponsePage result, Page pager, Conver conver) {
cover(result, pager);
List vos = new ArrayList();
List cs = pager.getContent();
if (cs != null) {
for (S item : cs) {
vos.add(conver.conver(item));
}
}
result.setList(vos);
return result;
}
public static ResponsePage coverPage(ResponsePage result, Pagination pager, Conver conver) {
cover(result, pager);
List vos = new ArrayList();
List cs = pager.getList();
if (cs != null) {
for (S item : cs) {
vos.add(conver.conver(item));
}
}
result.setList(vos);
return result;
}
public static ResponseList coverList(ResponseList result, Page pager, Conver conver) {
List vos = new ArrayList();
List cs = pager.getContent();
if (cs != null) {
for (S item : cs) {
vos.add(conver.conver(item));
}
}
result.setList(vos);
return result;
}
public static List coverList(List source, Conver conver) {
List vos = new ArrayList();
if (source != null) {
for (S item : source) {
vos.add(conver.conver(item));
}
}
return vos;
}
public static List coverCollect(Collection source, Conver conver) {
List vos = new ArrayList();
if (source != null) {
for (S item : source) {
vos.add(conver.conver(item));
}
}
return vos;
}
}