Class Paging
- java.lang.Object
-
- org.alfresco.repo.web.util.paging.Paging
-
public class Paging extends java.lang.Object
Paging. 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) Windowed 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. Pseudo-code for traversing through a collection of N items (10 at a time): Paging paging = new Paging(); Cursor page = paging.createCursor(N, paging.createPage(1, 10)); while (page.isInRange()) { for (long i = page.getStartRow(); i <= page.getEndRow(); i++) { ...collection[i]... } page = paging.createCursor(N, paging.createPage(page.getNextPage(), page.getPageSize()); } Cursor window = paging.createCursor(N, paging.createWindow(0, 10)); while (window.isInRange()) { for (long i = window.getStartRow(); i <= window.getEndRow(); i++) { ...collection[i]... } window = paging.createCursor(N, paging.createWindow(window.getNextPage(), window.getPageSize()); }- Author:
- davidc
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Paging.PageType
-
Constructor Summary
Constructors Constructor Description Paging()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Cursor
createCursor(int totalRows, Page page)
Create a CursorPage
createPage(int pageNumber, int pageSize)
Create a PagePagedResults
createPagedResult(java.lang.Object result, Cursor cursor)
Create a Paged Result SetPagedResults
createPagedResults(java.lang.Object[] results, Cursor cursor)
Create a Paged Result SetPage
createPageOrWindow(java.lang.Integer pageNumber, java.lang.Integer pageSize, java.lang.Integer skipCount, java.lang.Integer maxItems)
Create a Page or WindowPage
createPageOrWindow(java.util.Map<java.lang.String,java.lang.String> args)
Create a Page or Window from standardised request arguments For Paged based index (take precedence over window based index, if both are specified): - request args pageNo => page number index pageSize => size of page For Window based index (as defined by CMIS): - request args (take precedence over header values if both are specified) skipCount => row number start index maxItems => size of pagePage
createUnlimitedPage()
Create an unlimited PagePage
createWindow(int skipRows, int maxRows)
Create a Windowboolean
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
-
createPageOrWindow
public Page createPageOrWindow(java.util.Map<java.lang.String,java.lang.String> args)
Create a Page or Window from standardised request arguments For Paged based index (take precedence over window based index, if both are specified): - request args pageNo => page number index pageSize => size of page For Window based index (as defined by CMIS): - request args (take precedence over header values if both are specified) skipCount => row number start index maxItems => size of page- Parameters:
args
- request args- Returns:
- page (if pageNumber driven) or window (if skipCount driven)
-
createPageOrWindow
public Page createPageOrWindow(java.lang.Integer pageNumber, java.lang.Integer pageSize, java.lang.Integer skipCount, java.lang.Integer maxItems)
Create a Page or Window- Parameters:
pageNumber
- page number (optional and paired with pageSize)pageSize
- page size (optional and paired with pageNumber)skipCount
- skipCount (optional and paired with maxItems)maxItems
- maxItems (optional and paired with skipCount)- Returns:
- page (if pageNumber driven) or window (if skipCount driven)
-
createPage
public Page createPage(int pageNumber, int pageSize)
Create a Page- Parameters:
pageNumber
- page numberpageSize
- page size- Returns:
- the page
-
createUnlimitedPage
public Page createUnlimitedPage()
Create an unlimited Page- Returns:
- page (single Page starting at first page of unlimited page size)
-
createWindow
public Page createWindow(int skipRows, int maxRows)
Create a Window- Parameters:
skipRows
- number of rows to skipmaxRows
- maximum number of rows in window- Returns:
- the window
-
createCursor
public Cursor createCursor(int totalRows, Page page)
Create a Cursor- Parameters:
totalRows
- total number of rows in cursor (< 0 for don't know)page
- the page / window within cursor- Returns:
- the cursor
-
createPagedResults
public PagedResults createPagedResults(java.lang.Object[] results, Cursor cursor)
Create a Paged Result Set- Parameters:
results
- the results for the page within the cursorcursor
- the cursor- Returns:
- the paged result set
-
createPagedResult
public PagedResults createPagedResult(java.lang.Object result, Cursor cursor)
Create a Paged Result Set- Parameters:
result
- the results for the page within the cursorcursor
- the cursor- Returns:
- the paged result set
-
-