In cases when paging between different requests is not necessary (all results are consumed in the same request/thread) a common usage-pattern would be as such:
Page<V> page = .... get first page
while (page != null) {
for (V v : page.values()) {
...do something...
}
page = page.nextPage();
}
or
Page<V> page = .... get first page
do {
for (V v : page.values()) {
...do something...
}
page = page.nextPage();
} while (page != null);
To avoid this boilerplate code It would be nice to add to the Page class a method to return
an Iterator for all the results (and let that Iterator do the paging).
Some options:
(1) add a static method such as Page.iterateAll(page)
(2) an instance method such as page.allValues() or page.iterateAll() or page.fetchAll()
Any preference or other suggestions?
In cases when paging between different requests is not necessary (all results are consumed in the same request/thread) a common usage-pattern would be as such:
or
To avoid this boilerplate code It would be nice to add to the
Pageclass a method to returnan
Iteratorfor all the results (and let that Iterator do the paging).Some options:
(1) add a static method such as Page.iterateAll(page)
(2) an instance method such as
page.allValues()orpage.iterateAll()orpage.fetchAll()Any preference or other suggestions?