Pagination
Let us presume you have a list of 5 containers, like this:
alpha
beta
gamma
delta
epsilon
The most basic form of pagination is the way the OpenStack API implemented it. You have to pass the point from where to continue and a page size.
Collection<Container> containers = account.list(null, "beta", 2);
In this case, the next element after "beta" will be the starting point and a maximum of 2 elements will be added to the page. So the result will be:
gamma
delta
Using a PaginationMap
Although the OpenStack API allows pagination, it is done in a strange way. You have to pass the last record on the previous page plus the page size. Normally, you would expect to be able to pass a page and a page size. If you have to have knowledge of the previous page, you can hardly do things like showing the last page, unless you pass all the pages before it first.
JOSS has functionality with which you can simulate the page/page size way of pagination.
Let's presume you have an account, then you can build up a map based on a page size of 10 like so:
PaginationMap paginationMap = account.getPaginationMap(10);
You will get a map which is capable of converting a page to a marker, like described above.
If you want to go through all pages, it looks like this:
for (Integer page = 0; page < paginationMap.getNumberOfPages(); page++) {
System.out.println("PAGE: "+page);
for (Container container : account.list(paginationMap, page)) {
System.out.println(container.getName());
}
}
Note that the map is created once and NOT automatically refreshed, so if the underlying containers are added or deleted, this will not be shown. You will have to generate a new map to reflect the changed situation.
Filtering
You have a number of containers (or objects), but you only want to show the ones starting with a certain prefix. Let's suppose these are the container names you have:
alpha
prod-alpha
beta
prod-beta
gamma
prod-gamma
delta
prod-delta
epsilon
prod-epsilon
If you only want to page over the items starting with "prod-" this is what you do with the PaginationMap:
PaginationMap paginationMap = account.getPaginationMap("prod-", 2);
From there on, it works in the same way. So if you would be running the print loop shown in the section before this on, this would be your output:
PAGE 0
prod-alpha
prod-beta
PAGE 1
prod-gamma
prod-delta
PAGE 2
prod-epsilon