use of org.wso2.carbon.security.keystore.service.PaginatedCertData in project carbon-identity-framework by wso2.
the class KeyStoreAdmin method doPaging.
/**
* This method is used internally to do the pagination purposes.
*
* @param pageNumber page Number
* @param certDataSet set of keyStoreData
* @return PaginatedPolicySetDTO object containing the number of pages and the set of policies
* that reside in the given page.
*/
private PaginatedCertData doPaging(int pageNumber, CertData[] certDataSet) {
PaginatedCertData paginatedCertData = new PaginatedCertData();
if (certDataSet.length == 0) {
paginatedCertData.setCertDataSet(new CertData[0]);
return paginatedCertData;
}
int itemsPerPageInt = SecurityConstants.ITEMS_PER_PAGE;
int numberOfPages = (int) Math.ceil((double) certDataSet.length / itemsPerPageInt);
if (pageNumber > numberOfPages - 1) {
pageNumber = numberOfPages - 1;
}
int startIndex = pageNumber * itemsPerPageInt;
int endIndex = (pageNumber + SecurityConstants.CACHING_PAGE_SIZE) * itemsPerPageInt;
CertData[] returnedCertDataSet = new CertData[itemsPerPageInt * SecurityConstants.CACHING_PAGE_SIZE];
for (int i = startIndex, j = 0; i < endIndex && i < certDataSet.length; i++, j++) {
returnedCertDataSet[j] = certDataSet[i];
}
paginatedCertData.setCertDataSet(returnedCertDataSet);
paginatedCertData.setNumberOfPages(numberOfPages);
return paginatedCertData;
}
Aggregations