Skip to content

Commit

Permalink
Extend functionality for paged lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jianghaolu committed Apr 15, 2016
1 parent cea6f72 commit 4ff082d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion azure-client-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ uploadArchives {
repositories {
mavenDeployer {
configuration = configurations.deployerJars
snapshotRepository(url: "ftp://waws-prod-bay-005.ftp.azurewebsites.windows.net/site/wwwroot/") {
snapshotRepository(url: "file://\\\\aaptfile01\\ADXSDK\\Java\\internal-snapshots") {
authentication(userName: username, password: password)
}
pom.setArtifactId "azure-client-runtime"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.microsoft.rest.RestException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
Expand All @@ -30,6 +31,12 @@ public abstract class PagedList<E> implements List<E> {
private List<E> items;
/** Stores the link to get the next page of items. */
private String nextPageLink;
/** Stores the latest page fetched. */
private Page<E> currentPage;

public PagedList() {
items = new ArrayList<>();
}

/**
* Creates an instance of PagedList from a {@link Page} response.
Expand All @@ -39,6 +46,7 @@ public abstract class PagedList<E> implements List<E> {
public PagedList(Page<E> page) {
items = page.getItems();
nextPageLink = page.getNextPageLink();
currentPage = page;
}

/**
Expand Down Expand Up @@ -69,12 +77,12 @@ public void loadNextPage() {
Page<E> nextPage = nextPage(this.nextPageLink);
this.nextPageLink = nextPage.getNextPageLink();
this.items.addAll(nextPage.getItems());
this.currentPage = nextPage;
} catch (RestException e) {
throw new WebServiceException(e.toString(), e);
} catch (IOException e) {
throw new DataBindingException(e.getMessage(), e);
}

}

/**
Expand All @@ -86,6 +94,24 @@ public void loadAll() {
}
}

/**
* Gets the latest page fetched.
*
* @return the latest page.
*/
public Page<E> currentPage() {
return currentPage;
}

/**
* Gets the next page's link.
*
* @return the next page link.
*/
public String nextPageLink() {
return nextPageLink;
}

/**
* The implementation of {@link ListIterator} for PagedList.
*/
Expand Down

0 comments on commit 4ff082d

Please sign in to comment.