Pager
8751 단어 PAGER
import java.util.ArrayList;
import java.util.List;
public class Pager {
public int currentPage = 0;
private int nextPage;
private int previousPage;
private int fristPage;
public int lastPage;
private int pageSize = 10;
private int record_cnt = 67;
public List<String> currentRecords;
public List<String> allRecords;
public Pager(List<String> _allRecords, int _pageSize) {
this.pageSize = _pageSize;
allRecords = _allRecords;
record_cnt = allRecords.size();
lastPage = this.record_cnt / this.pageSize + 1;
}
public int getCurrentPage() {
return currentPage;
}
private int getNextPageNum() {
if (currentPage < lastPage) {
nextPage = currentPage + 1;
} else {
nextPage = lastPage;
}
return nextPage;
}
public List<String> getJumpPageRecords(int jumpPage) {
if (jumpPage >= this.lastPage) {
return this.getLastPageRecords();
} else if (jumpPage <= this.fristPage) {
return this.getFirstPageRecords();
} else {
this.currentRecords = new ArrayList<String>();
for (int i = (jumpPage - 1) * pageSize; i < jumpPage * pageSize; i++) {
this.currentRecords.add(this.allRecords.get(i));
}
this.currentPage = jumpPage;
return currentRecords;
}
}
public List<String> getNextPageRecords() {
getNextPageNum();
if (this.currentPage == lastPage) {
System.out.println("Already was the last page!!!");
return null;
}
if (nextPage == this.lastPage) {
return this.getLastPageRecords();
} else {
this.currentRecords = new ArrayList<String>();
for (int i = currentPage * pageSize; i < nextPage * pageSize; i++) {
this.currentRecords.add(this.allRecords.get(i));
}
currentPage = nextPage;
return currentRecords;
}
}
public List<String> getPreviousPageRecords() {
this.getPreviousPage();
if (this.currentPage == 1) {
System.out.println("Already was the first page!!!");
return null;
}
if (previousPage == 1) {
return this.getFirstPageRecords();
} else {
this.currentRecords = new ArrayList<String>();
for (int i = (previousPage - 1) * pageSize; i < previousPage
* pageSize; i++) {
this.currentRecords.add(this.allRecords.get(i));
}
currentPage = previousPage;
return currentRecords;
}
}
public List<String> getFirstPageRecords() {
if (lastPage == 1) {
return this.allRecords;
} else {
this.currentRecords = new ArrayList<String>();
for (int i = 0; i < this.pageSize; i++) {
this.currentRecords.add(allRecords.get(i));
}
this.currentPage = 1;
return currentRecords;
}
}
public List<String> getLastPageRecords() {
if (lastPage == 1) {
return this.allRecords;
} else {
this.currentRecords = new ArrayList<String>();
for (int i = (lastPage - 1) * pageSize; i < this.record_cnt; i++) {
this.currentRecords.add(allRecords.get(i));
}
this.currentPage = lastPage;
return currentRecords;
}
}
private int getPreviousPage() {
if (this.currentPage > 1) {
previousPage = currentPage - 1;
} else {
previousPage = 1;
}
return previousPage;
}
public int getFristPage() {
fristPage = 0;
return fristPage;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
// public List<String>
public static void main(String[] args) {
List<String> pageRecords = new ArrayList<String>();
for (int i = 1; i <= 59; i++) {
pageRecords.add("-+-" + i + "---");
}
Pager p = new Pager(pageRecords, 5);
System.out.println("all: " + p.lastPage);
List<String> r = p.getJumpPageRecords(2);
if (r != null) {
for (String a : r) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r2 = p.getNextPageRecords();
if (r2 != null) {
for (String a : r2) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r3 = p.getNextPageRecords();
if (r3 != null) {
for (String a : r3) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r4 = p.getPreviousPageRecords();
if (r4 != null) {
for (String a : r4) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r5 = p.getFirstPageRecords();
if (r5 != null) {
for (String a : r5) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r6 = p.getLastPageRecords();
if (r6 != null) {
for (String a : r6) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r7 = p.getNextPageRecords();
if (r7 != null) {
for (String a : r7) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r8 = p.getFirstPageRecords();
if (r8 != null) {
for (String a : r8) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
List<String> r9 = p.getPreviousPageRecords();
if (r9 != null) {
for (String a : r9) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
for (int i = 0; i < 17; i++) {
List<String> r12 = p.getNextPageRecords();
if (r12 != null) {
for (String a : r12) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
}
for (int i = 0; i < 12; i++) {
List<String> r12 = p.getPreviousPageRecords();
if (r12 != null) {
for (String a : r12) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
}
List<String> r11 = p.getJumpPageRecords(9);
if (r11 != null) {
for (String a : r11) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
for (int i = 0; i < 19; i++) {
List<String> r12 = p.getPreviousPageRecords();
if (r12 != null) {
for (String a : r12) {
System.out.print(a + " | ");
}
System.out.println();
System.out.println("--------current page is :" + p.currentPage
+ " --------");
}
}
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
DataPager 페이지 나누기 스타일(css)Paged ControlID = "LV"는 asp:ListView ID = "LV"에 해당합니다. current.css...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.