Package org.alfresco.repo.web.util
Class PagingCursor
- java.lang.Object
-
- org.alfresco.repo.web.util.PagingCursor
-
public class PagingCursor extends Object
Paging cursor. A utility for maintaining paged indexes for a collection of N items. There are two types of cursor: a) Paged This type of cursor is driven from a page number and page size. Random access within the collection is possible by jumping straight to a page. A simple scroll through the collection is supported by iterating through each next page. b) Rows This type of cursor is driven from a skip row count and maximum number of rows. Random access is not supported. The collection of items is simply scrolled through from start to end by iterating through each next set of rows. In either case, a paging cursor provides a start row and end row which may be used to extract the items for the page from the collection of N items. A zero (or less) page size or row maximum means "unlimited". Zero or one based Page and Rows indexes are supported. By default, Pages are 1 based and Rows are 0 based. At any time, -1 is returned to represent "out of range" i.e. for next, previous, last page and next skip count. Pseudo-code for traversing through a collection of N items (10 at a time): PagingCursor cursor = new PagingCursor(); Page page = cursor.createPageCursor(N, 10, 1); while (page.isInRange()) { for (long i = page.getStartRow(); i <= page.getEndRow(); i++) { ...collection[i]... } page = cursor.createPageCursor(N, 10, page.getNextPage()); } Rows rows = cursor.createRowsCursor(N, 10, 0); while (rows.isInRange()) { for (long i = page.getStartRow(); i <= page.getEndRow(); i++) { ...collection[i]... } rows = cursor.createRowsCursor(N, 10, rows.getNextSkipRows()); }- Author:
- davidc
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PagingCursor.Page
Page based Cursorstatic class
PagingCursor.Rows
Rows based Cursor
-
Constructor Summary
Constructors Constructor Description PagingCursor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PagingCursor.Page
createPageCursor(long totalRows, int rowsPerPage, int page)
Create a Page based CursorPagingCursor.Page
createPageCursor(long totalRows, int rowsPerPage, int page, boolean zeroBasedPage, boolean zeroBasedRow)
Create a Page based CursorPagingCursor.Rows
createRowsCursor(long totalRows, long maxRows, long skipRows)
Create a Rows based CursorPagingCursor.Rows
createRowsCursor(long totalRows, long maxRows, long skipRows, boolean zeroBasedRow)
Create a Rows based Cursorboolean
isZeroBasedPage()
Is zero based page index? Note: scoped to this paging cursor instanceboolean
isZeroBasedRow()
Is zero based row index? Note: scoped to this paging cursor instancevoid
setZeroBasedPage(boolean zeroBasedPage)
Sets zero based page index Note: scoped to this paging cursor instancevoid
setZeroBasedRow(boolean zeroBasedRow)
Sets zero based row index Note: scoped to this paging cursor instance
-
-
-
Method Detail
-
setZeroBasedPage
public void setZeroBasedPage(boolean zeroBasedPage)
Sets zero based page index Note: scoped to this paging cursor instance- Parameters:
zeroBasedPage
- true => 0 based, false => 1 based
-
isZeroBasedPage
public boolean isZeroBasedPage()
Is zero based page index? Note: scoped to this paging cursor instance- Returns:
- true => 0 based, false => 1 based
-
setZeroBasedRow
public void setZeroBasedRow(boolean zeroBasedRow)
Sets zero based row index Note: scoped to this paging cursor instance- Parameters:
zeroBasedRow
- true => 0 based, false => 1 based
-
isZeroBasedRow
public boolean isZeroBasedRow()
Is zero based row index? Note: scoped to this paging cursor instance- Returns:
- true => 0 based, false => 1 based
-
createPageCursor
public PagingCursor.Page createPageCursor(long totalRows, int rowsPerPage, int page)
Create a Page based Cursor- Parameters:
totalRows
- total rows in collectionrowsPerPage
- page sizepage
- page number (0 or 1 based)- Returns:
- Page Cursor
-
createPageCursor
public PagingCursor.Page createPageCursor(long totalRows, int rowsPerPage, int page, boolean zeroBasedPage, boolean zeroBasedRow)
Create a Page based Cursor- Parameters:
totalRows
- total rows in collectionrowsPerPage
- page sizepage
- page number (0 or 1 based)zeroBasedPage
- true => 0 based, false => 1 basedzeroBasedRow
- true => 0 based, false => 1 based- Returns:
- Page Cursor
-
createRowsCursor
public PagingCursor.Rows createRowsCursor(long totalRows, long maxRows, long skipRows)
Create a Rows based Cursor- Parameters:
totalRows
- total rows in collectionmaxRows
- maximum number of rows in pageskipRows
- number of rows to skip (0 - none)- Returns:
- Rows Cursor
-
createRowsCursor
public PagingCursor.Rows createRowsCursor(long totalRows, long maxRows, long skipRows, boolean zeroBasedRow)
Create a Rows based Cursor- Parameters:
totalRows
- total rows in collectionmaxRows
- maximum number of rows in pageskipRows
- number of rows to skip (0 - none)zeroBasedRow
- true => 0 based, false => 1 based- Returns:
- Rows Cursor
-
-