Skip to content

Commit

Permalink
Merge pull request #68 from aozarov/temp1
Browse files Browse the repository at this point in the history
adding an option to page from ListResult
  • Loading branch information
aozarov committed May 19, 2015
2 parents 3396968 + 971fc63 commit c081812
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 55 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/google/gcloud/ServiceOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public AuthCredentials authCredentials() {
}

public RetryParams retryParams() {
return retryParams;
return retryParams != null ? retryParams : RetryParams.noRetries();
}

public ServiceRpcFactory<R, O> serviceRpcFactory() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class DatastoreServiceOptions extends ServiceOptions<DatastoreRpc, Datast
private final String namespace;
private final boolean force;
private final boolean normalizeDataset;
private transient DatastoreRpc datastoreRpc;

public static class Builder extends
ServiceOptions.Builder<DatastoreRpc, DatastoreServiceOptions, Builder> {
Expand Down Expand Up @@ -178,10 +179,15 @@ public boolean equals(Object obj) {
}

DatastoreRpc datastoreRpc() {
if (datastoreRpc != null) {
return datastoreRpc;
}
if (serviceRpcFactory() != null) {
return serviceRpcFactory().create(this);
datastoreRpc = serviceRpcFactory().create(this);
} else {
datastoreRpc = ServiceRpcProvider.datastore(this);
}
return ServiceRpcProvider.datastore(this);
return datastoreRpc;
}

public static DatastoreServiceOptions defaultInstance() {
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/gcloud/storage/BatchRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ public boolean equals(Object obj) {
&& Objects.equals(toGet, other.toGet);
}

Map<Blob, Iterable<BlobSourceOption>> toDelete() {
public Map<Blob, Iterable<BlobSourceOption>> toDelete() {
return toDelete;
}

Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
public Map<Blob, Iterable<BlobTargetOption>> toUpdate() {
return toUpdate;
}

Map<Blob, Iterable<BlobSourceOption>> toGet() {
public Map<Blob, Iterable<BlobSourceOption>> toGet() {
return toGet;
}

Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/google/gcloud/storage/BatchResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public static class Result<T extends Serializable> implements Serializable {
private final StorageServiceException exception;


Result(T value) {
public Result(T value) {
this.value = value;
this.exception = null;
}

Result(StorageServiceException exception) {
public Result(StorageServiceException exception) {
this.exception = exception;
this.value = null;
}
Expand Down Expand Up @@ -112,7 +112,7 @@ static <T extends Serializable> Result<T> empty() {
}
}

BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
public BatchResponse(List<Result<Boolean>> deleteResult, List<Result<Blob>> updateResult,
List<Result<Blob>> getResult) {
this.deleteResult = ImmutableList.copyOf(deleteResult);
this.updateResult = ImmutableList.copyOf(updateResult);
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/google/gcloud/storage/ListResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,35 @@ public final class ListResult<T extends Serializable> implements Iterable<T>, Se

private final String cursor;
private final Iterable<T> results;
private final NextPageFetcher<T> pageFetcher;

ListResult(String cursor, Iterable<T> results) {
interface NextPageFetcher<T extends Serializable> extends Serializable {
ListResult<T> nextPage();
}

public ListResult(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
this.pageFetcher = pageFetcher;
this.cursor = cursor;
this.results = results;
}

/**
* Returns the cursor for the nextPage or {@code null} if no more results.
*/
public String nextPageCursor() {
return cursor;
}

/**
* Returns the results of the nextPage or {@code null} if no more result.
*/
public ListResult<T> nextPage() {
if (cursor == null || pageFetcher == null) {
return null;
}
return pageFetcher.nextPage();
}

@Override
public Iterator<T> iterator() {
return results == null ? Collections.<T>emptyIterator() : results.iterator();
Expand Down
Loading

0 comments on commit c081812

Please sign in to comment.