The simplest Java page-splitting algorithm

Source: Internet
Author: User
pagination | The algorithm defines two vectors, one for storing the totalv of all records, the other for storing the records of the current page Currentpagev;
Total number of records: int totalsize = Totalv.getsize ();
Number of records displayed per page: int countperpage;
Total pages: int totalpagenum = totalsize/countperpage;
If the total number of records and the remainder of the records per page is greater than 0,
Then the total number of pages for their divisible result plus a
if (Totalsize%countperpage > 0) {
Totalpagenum = totalsize/countperpage + 1;
}
Current number of pages: Pagenum;

for (int j = 0;j<totalv.size (); j + +) {
Paging, taking records from TOTALV based on the current number of pages and how many records are displayed per page
Add a record to the Currentpagev;
If the current record is on (current page 1) * Display the number of records per page (including equals)
and the current page number * Each page shows the number of records (excluding equals) between the time;
Data that belongs to the page
if ((J >= (pageNum-1) * countperpage) && (J < Pagenum * Countperpage)) {
Currentpagev.addelement (Totalv.get (j));
}
When the number of Currentpagev records equals the number of records displayed per page,
Stop adding records to Currentpagev
if (currentpagev.size () = = Countperpage) {
Break
}
}
The record that is displayed in the current page, then, is the record in the Currentpagev.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.