Merged 5.2.N (5.2.1) to HEAD (5.2)

129196 mmuller: Merged RETURN-OF-THE-API (5.2.0) to 5.2.N (5.2.1)
      129052 adavis: REPO-232,REPO-883 V1 REST API: Sites Live Search (/queries/live-search-sites)
         - As part of code review: Added generics to listPage method and moved it inside AbstractQuery.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@129370 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Alexandru Epure
2016-08-09 14:17:05 +00:00
parent fb920495ad
commit 87f28f265b

View File

@@ -610,40 +610,40 @@ public class QueriesImpl implements Queries, InitializingBean
} }
return nodeRefs; return nodeRefs;
} }
}
// note: see also AbstractNodeRelation // note: see also AbstractNodeRelation
protected static CollectionWithPagingInfo listPage(List result, Paging paging) protected static <T> CollectionWithPagingInfo<T> listPage(List<T> result, Paging paging)
{
// return 'page' of results (based on full result set)
int skipCount = paging.getSkipCount();
int pageSize = paging.getMaxItems();
int pageEnd = skipCount + pageSize;
final List page = new ArrayList<>(pageSize);
if (result == null)
{ {
result = Collections.emptyList(); // return 'page' of results (based on full result set)
} int skipCount = paging.getSkipCount();
int pageSize = paging.getMaxItems();
int pageEnd = skipCount + pageSize;
Iterator it = result.iterator(); final List<T> page = new ArrayList<>(pageSize);
for (int counter = 0; counter < pageEnd && it.hasNext(); counter++) if (result == null)
{
Object element = it.next();
if (counter < skipCount)
{ {
continue; result = Collections.emptyList();
} }
if (counter > pageEnd - 1)
Iterator<T> it = result.iterator();
for (int counter = 0; counter < pageEnd && it.hasNext(); counter++)
{ {
break; T element = it.next();
if (counter < skipCount)
{
continue;
}
if (counter > pageEnd - 1)
{
break;
}
page.add(element);
} }
page.add(element);
int totalCount = result.size();
boolean hasMoreItems = ((skipCount + page.size()) < totalCount);
return CollectionWithPagingInfo.asPaged(paging, page, hasMoreItems, totalCount);
} }
int totalCount = result.size();
boolean hasMoreItems = ((skipCount + page.size()) < totalCount);
return CollectionWithPagingInfo.asPaged(paging, page, hasMoreItems, totalCount);
} }
} }