public class PageUtil {
public static Integer DEFAULT_PAGE = 1;
public static Integer DEFAULT_COUNT = 10;
public static Integer getStart(Integer page, Integer count) {
if (null == page || page.compareTo(1) < 0) {
page = DEFAULT_PAGE;
}
if (null == count || count.compareTo(1) < 0) {
count = DEFAULT_COUNT;
}
return (page - 1) * count;
}
public static Integer getStart(Integer page) {
if (null == page || page.compareTo(1) < 0) {
page = DEFAULT_PAGE;
}
if (null == DEFAULT_COUNT || DEFAULT_COUNT.compareTo(1) < 0) {
DEFAULT_COUNT = DEFAULT_COUNT;
}
return (page - 1) * DEFAULT_COUNT;
}
public static Integer getRows(Integer count) {
if (null == count || count.compareTo(1) < 0) {
return DEFAULT_COUNT;
}
return count;
}
public static Integer getPages(Integer total) {
int pages = total / DEFAULT_COUNT;
if (total % DEFAULT_COUNT != 0) {
pages = pages + 1;
}
if (pages == 0) {
pages = 1;
}
return pages;
}
public static Integer getPages(Integer total, Integer count) {
if (null == count
|| null == total
|| count < 1
|| total < 1
|| count >= total) {
return 1;
}
int pages = total / count;
if (total % count != 0) {
pages = pages + 1;
}
if (pages == 0) {
pages = 1;
}
return pages;
}
public static void main(String[] args) {
System.err.println(getPages(11, 10));
}
}