forked from nibnait/algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageUtils.java
More file actions
55 lines (46 loc) · 1.73 KB
/
PageUtils.java
File metadata and controls
55 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package common.util;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Lists;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.function.Function;
import java.util.function.IntFunction;
import java.util.stream.Collectors;
public class PageUtils {
public static <T, R> PageInfo<R> convertPageInfo(PageInfo<T> sourcePage, List<R> list) {
if (sourcePage == null) {
return new PageInfo<>();
}
PageInfo<R> newPageInfo = CommonBeanUtil.copyProperties(sourcePage, PageInfo::new);
if (newPageInfo == null || CollectionUtils.isEmpty(list)) {
newPageInfo.setList(list);
return newPageInfo;
}
newPageInfo.setList(list);
return newPageInfo;
}
public static <T, R> PageInfo<R> convertPageInfo(PageInfo<T> sourcePage, Function<T, R> function) {
if (sourcePage == null) {
return new PageInfo<>();
}
PageInfo<R> newPageInfo = CommonBeanUtil.copyProperties(sourcePage, PageInfo::new);
if (newPageInfo == null || sourcePage.getList() == null) {
return newPageInfo;
}
newPageInfo.setList(sourcePage.getList().stream().map(function).collect(Collectors.toList()));
return newPageInfo;
}
public static <T> List<T> getPageInfoTotalList(IntFunction<PageInfo<T>> intFunction) {
List<T> list = Lists.newArrayList();
int pageNum = 1;
PageInfo<T> pageInfo;
do {
pageInfo = intFunction.apply(pageNum++);
if (pageInfo == null) {
break;
}
list.addAll(pageInfo.getList());
} while (pageInfo.isHasNextPage());
return list;
}
}