View Javadoc
1   package com.foxinmy.weixin4j.model.paging;
2   
3   import java.io.Serializable;
4   import java.util.Iterator;
5   import java.util.List;
6   
7   public class Pagedata<T> implements Serializable, Iterable<T> {
8   
9   	private static final long serialVersionUID = 163159826528502864L;
10  
11  	private final int total;
12  	private final Pageable pageable;
13  	private final List<T> content;
14  
15  	public Pagedata(Pageable pageable, int total, List<T> content) {
16  		this.pageable = pageable;
17  		this.total = total;
18  		this.content = content;
19  	}
20  
21  	public int getNumber() {
22  		return pageable == null ? 0 : pageable.getPageNumber();
23  	}
24  
25  	public int getSize() {
26  		return pageable == null ? 0 : pageable.getPageSize();
27  	}
28  
29  	public int getTotalPages() {
30  		return getSize() == 0 ? 1 : (int) Math.ceil((double) total
31  				/ (double) getSize());
32  	}
33  
34  	public int getTotalElements() {
35  		return total;
36  	}
37  
38  	public int getNumberOfElements() {
39  		return hasContent() ? 0 : content.size();
40  	}
41  
42  	public boolean hasContent() {
43  		return content != null && !content.isEmpty();
44  	}
45  
46  	public boolean hasPrevious() {
47  		return pageable == null ? false : pageable.hasPrevious();
48  	}
49  
50  	public boolean hasNext() {
51  		return getNumber() + 1 < getTotalPages();
52  	}
53  
54  	public Sort getSort() {
55  		return pageable == null ? null : pageable.getSort();
56  	}
57  
58  	public List<T> getContent() {
59  		return content;
60  	}
61  
62  	@Override
63  	public Iterator<T> iterator() {
64  		return hasContent() ? content.iterator() : null;
65  	}
66  
67  	@Override
68  	public String toString() {
69  		return "Pagedata [total=" + total + ", pageable=" + pageable + "]";
70  	}
71  }