From 31794efeaf56a1fa357eb8b45c44ff3bb340b3bd Mon Sep 17 00:00:00 2001 From: Jianghao Lu Date: Wed, 16 Mar 2016 15:33:44 -0700 Subject: [PATCH] Add lazy behavior in get() --- .../src/main/java/com/microsoft/azure/PagedList.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java b/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java index a300ff6a3e2ac..cdd38a5ca3a13 100644 --- a/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java +++ b/azure-client-runtime/src/main/java/com/microsoft/azure/PagedList.java @@ -235,6 +235,17 @@ public void clear() { @Override public E get(int index) { + while (index >= items.size() && nextPageLink != null) { + try { + Page nextPage = loadPage(nextPageLink); + nextPageLink = nextPage.getNextPageLink(); + addAll(nextPage.getItems()); + } catch (CloudException e) { + throw new WebServiceException(e.toString(), e); + } catch (IOException e) { + throw new DataBindingException(e.getMessage(), e); + } + } return items.get(index); }