Skip to content

Commit ea36a9e

Browse files
committed
Rename ListResult and move to core module
1 parent 33bfb1e commit ea36a9e

12 files changed

Lines changed: 103 additions & 92 deletions

File tree

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BaseListResult.java renamed to gcloud-java-core/src/main/java/com/google/gcloud/BasePage.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.storage;
17+
package com.google.gcloud;
1818

1919
import java.io.Serializable;
2020
import java.util.Collections;
2121
import java.util.Iterator;
2222
import java.util.Objects;
2323

2424
/**
25-
* Base implementation for Google Cloud storage list result.
25+
* Base implementation for Google Cloud paginated results.
2626
*/
27-
public class BaseListResult<T extends Serializable> implements ListResult<T>, Serializable {
27+
public class BasePage<T extends Serializable> implements Page<T>, Serializable {
2828

2929
private static final long serialVersionUID = -6937287874908527950L;
3030

@@ -33,10 +33,10 @@ public class BaseListResult<T extends Serializable> implements ListResult<T>, Se
3333
private final NextPageFetcher<T> pageFetcher;
3434

3535
public interface NextPageFetcher<T extends Serializable> extends Serializable {
36-
ListResult<T> nextPage();
36+
Page<T> nextPage();
3737
}
3838

39-
public BaseListResult(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
39+
public BasePage(NextPageFetcher<T> pageFetcher, String cursor, Iterable<T> results) {
4040
this.pageFetcher = pageFetcher;
4141
this.cursor = cursor;
4242
this.results = results;
@@ -48,7 +48,7 @@ public String nextPageCursor() {
4848
}
4949

5050
@Override
51-
public ListResult<T> nextPage() {
51+
public Page<T> nextPage() {
5252
if (cursor == null || pageFetcher == null) {
5353
return null;
5454
}
@@ -67,10 +67,10 @@ public int hashCode() {
6767

6868
@Override
6969
public boolean equals(Object obj) {
70-
if (!(obj instanceof BaseListResult)) {
70+
if (!(obj instanceof BasePage)) {
7171
return false;
7272
}
73-
BaseListResult<?> other = (BaseListResult<?>) obj;
73+
BasePage<?> other = (BasePage<?>) obj;
7474
return Objects.equals(cursor, other.cursor)
7575
&& Objects.equals(results, other.results);
7676
}

gcloud-java-storage/src/main/java/com/google/gcloud/storage/ListResult.java renamed to gcloud-java-core/src/main/java/com/google/gcloud/Page.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.storage;
17+
package com.google.gcloud;
1818

1919
/**
20-
* Interface for Google Cloud storage list result.
20+
* Interface for Google Cloud paginated results.
2121
*/
22-
public interface ListResult<T> extends Iterable<T> {
22+
public interface Page<T> extends Iterable<T> {
2323

2424
/**
2525
* Returns the cursor for the nextPage or {@code null} if no more results.
2626
*/
2727
String nextPageCursor();
2828

2929
/**
30-
* Returns the results of the nextPage or {@code null} if no more result.
30+
* Returns the next page of results or {@code null} if no more result.
3131
*/
32-
ListResult<T> nextPage();
32+
Page<T> nextPage();
3333

3434
}

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BaseListResultTest.java renamed to gcloud-java-core/src/test/java/com/google/gcloud/BasePageTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,32 @@
1414
* limitations under the License.
1515
*/
1616

17-
package com.google.gcloud.storage;
17+
package com.google.gcloud;
1818

1919
import static org.junit.Assert.assertEquals;
2020

2121
import com.google.common.collect.ImmutableList;
22+
import com.google.gcloud.BasePage;
2223

2324
import org.junit.Test;
2425

2526
import java.util.Collections;
2627

27-
public class BaseListResultTest {
28+
public class BasePageTest {
2829

2930
@Test
30-
public void testListResult() throws Exception {
31+
public void testPage() throws Exception {
3132
ImmutableList<String> values = ImmutableList.of("1", "2");
32-
final BaseListResult<String> nextResult =
33-
new BaseListResult<>(null, "c", Collections.<String>emptyList());
34-
BaseListResult.NextPageFetcher<String> fetcher = new BaseListResult.NextPageFetcher<String>() {
33+
final BasePage<String> nextResult =
34+
new BasePage<>(null, "c", Collections.<String>emptyList());
35+
BasePage.NextPageFetcher<String> fetcher = new BasePage.NextPageFetcher<String>() {
3536

3637
@Override
37-
public BaseListResult<String> nextPage() {
38+
public BasePage<String> nextPage() {
3839
return nextResult;
3940
}
4041
};
41-
BaseListResult<String> result = new BaseListResult<>(fetcher, "c", values);
42+
BasePage<String> result = new BasePage<>(fetcher, "c", values);
4243
assertEquals(nextResult, result.nextPage());
4344
assertEquals("c", result.nextPageCursor());
4445
assertEquals(values, ImmutableList.copyOf(result.iterator()));

gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobListResult.java renamed to gcloud-java-storage/src/main/java/com/google/gcloud/storage/BlobPage.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@
2020

2121
import com.google.common.base.Function;
2222
import com.google.common.collect.Iterators;
23+
import com.google.gcloud.Page;
2324

2425
import java.util.Iterator;
2526
import java.util.Objects;
2627

2728
/**
2829
* Implementation of a paginated list of Google Cloud storage {@code Blob}.
2930
*/
30-
public class BlobListResult implements ListResult<Blob> {
31+
public class BlobPage implements Page<Blob> {
3132

32-
private final ListResult<BlobInfo> infoList;
33+
private final Page<BlobInfo> infoList;
3334
private final Storage storage;
3435

35-
public BlobListResult(Storage storage, ListResult<BlobInfo> infoList) {
36+
public BlobPage(Storage storage, Page<BlobInfo> infoList) {
3637
this.storage = checkNotNull(storage);
3738
this.infoList = checkNotNull(infoList);
3839
}
@@ -43,12 +44,12 @@ public String nextPageCursor() {
4344
}
4445

4546
@Override
46-
public ListResult<Blob> nextPage() {
47-
ListResult<BlobInfo> nextPageInfoList = infoList.nextPage();
47+
public Page<Blob> nextPage() {
48+
Page<BlobInfo> nextPageInfoList = infoList.nextPage();
4849
if (nextPageInfoList == null) {
4950
return null;
5051
}
51-
return new BlobListResult(storage, nextPageInfoList);
52+
return new BlobPage(storage, nextPageInfoList);
5253
}
5354

5455
@Override
@@ -68,10 +69,10 @@ public int hashCode() {
6869

6970
@Override
7071
public boolean equals(Object obj) {
71-
if (!(obj instanceof BlobListResult)) {
72+
if (!(obj instanceof BlobPage)) {
7273
return false;
7374
}
74-
BlobListResult other = (BlobListResult) obj;
75+
BlobPage other = (BlobPage) obj;
7576
return Objects.equals(infoList, other.infoList);
7677
}
7778
}

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Bucket.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import static com.google.common.base.Preconditions.checkNotNull;
2121

2222
import com.google.common.base.MoreObjects;
23+
import com.google.gcloud.Page;
2324
import com.google.gcloud.storage.Storage.BlobSourceOption;
2425
import com.google.gcloud.storage.Storage.BlobTargetOption;
2526
import com.google.gcloud.storage.Storage.BlobWriteOption;
@@ -134,8 +135,8 @@ public boolean delete(BucketSourceOption... options) {
134135
* @param options options for listing blobs
135136
* @throws StorageException upon failure
136137
*/
137-
public ListResult<Blob> list(Storage.BlobListOption... options) {
138-
return new BlobListResult(storage, storage.list(info.name(), options));
138+
public Page<Blob> list(Storage.BlobListOption... options) {
139+
return new BlobPage(storage, storage.list(info.name(), options));
139140
}
140141

141142
/**

gcloud-java-storage/src/main/java/com/google/gcloud/storage/Storage.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.common.collect.Lists;
2525
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
2626
import com.google.gcloud.Service;
27+
import com.google.gcloud.Page;
2728
import com.google.gcloud.spi.StorageRpc;
2829
import com.google.gcloud.spi.StorageRpc.Tuple;
2930

@@ -827,14 +828,14 @@ private static void checkContentType(BlobInfo blobInfo) throws IllegalArgumentEx
827828
*
828829
* @throws StorageException upon failure
829830
*/
830-
ListResult<BucketInfo> list(BucketListOption... options);
831+
Page<BucketInfo> list(BucketListOption... options);
831832

832833
/**
833834
* List the bucket's blobs.
834835
*
835836
* @throws StorageException upon failure
836837
*/
837-
ListResult<BlobInfo> list(String bucket, BlobListOption... options);
838+
Page<BlobInfo> list(String bucket, BlobListOption... options);
838839

839840
/**
840841
* Update bucket information.

gcloud-java-storage/src/main/java/com/google/gcloud/storage/StorageImpl.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@
4444
import com.google.common.io.BaseEncoding;
4545
import com.google.common.primitives.Ints;
4646
import com.google.gcloud.AuthCredentials.ServiceAccountAuthCredentials;
47+
import com.google.gcloud.BasePage;
4748
import com.google.gcloud.BaseService;
4849
import com.google.gcloud.ExceptionHandler;
4950
import com.google.gcloud.ExceptionHandler.Interceptor;
5051
import com.google.gcloud.RetryHelper.RetryHelperException;
52+
import com.google.gcloud.Page;
5153
import com.google.gcloud.spi.StorageRpc;
5254
import com.google.gcloud.spi.StorageRpc.RewriteResponse;
5355
import com.google.gcloud.spi.StorageRpc.Tuple;
@@ -224,7 +226,7 @@ public BlobInfo get(BlobId blob) {
224226
}
225227

226228
private abstract static class BasePageFetcher<T extends Serializable>
227-
implements BaseListResult.NextPageFetcher<T> {
229+
implements BasePage.NextPageFetcher<T> {
228230

229231
private static final long serialVersionUID = 8236329004030295223L;
230232
protected final Map<StorageRpc.Option, ?> requestOptions;
@@ -256,7 +258,7 @@ private static class BucketPageFetcher extends BasePageFetcher<BucketInfo> {
256258
}
257259

258260
@Override
259-
public ListResult<BucketInfo> nextPage() {
261+
public Page<BucketInfo> nextPage() {
260262
return listBuckets(serviceOptions, requestOptions);
261263
}
262264
}
@@ -273,17 +275,17 @@ private static class BlobPageFetcher extends BasePageFetcher<BlobInfo> {
273275
}
274276

275277
@Override
276-
public ListResult<BlobInfo> nextPage() {
278+
public Page<BlobInfo> nextPage() {
277279
return listBlobs(bucket, serviceOptions, requestOptions);
278280
}
279281
}
280282

281283
@Override
282-
public ListResult<BucketInfo> list(BucketListOption... options) {
284+
public Page<BucketInfo> list(BucketListOption... options) {
283285
return listBuckets(options(), optionMap(options));
284286
}
285287

286-
private static ListResult<BucketInfo> listBuckets(final StorageOptions serviceOptions,
288+
private static Page<BucketInfo> listBuckets(final StorageOptions serviceOptions,
287289
final Map<StorageRpc.Option, ?> optionsMap) {
288290
try {
289291
Tuple<String, Iterable<com.google.api.services.storage.model.Bucket>> result = runWithRetries(
@@ -302,19 +304,19 @@ public BucketInfo apply(com.google.api.services.storage.model.Bucket bucketPb) {
302304
return BucketInfo.fromPb(bucketPb);
303305
}
304306
});
305-
return new BaseListResult<>(new BucketPageFetcher(serviceOptions, cursor, optionsMap), cursor,
307+
return new BasePage<>(new BucketPageFetcher(serviceOptions, cursor, optionsMap), cursor,
306308
buckets);
307309
} catch (RetryHelperException e) {
308310
throw StorageException.translateAndThrow(e);
309311
}
310312
}
311313

312314
@Override
313-
public ListResult<BlobInfo> list(final String bucket, BlobListOption... options) {
315+
public Page<BlobInfo> list(final String bucket, BlobListOption... options) {
314316
return listBlobs(bucket, options(), optionMap(options));
315317
}
316318

317-
private static ListResult<BlobInfo> listBlobs(final String bucket,
319+
private static Page<BlobInfo> listBlobs(final String bucket,
318320
final StorageOptions serviceOptions, final Map<StorageRpc.Option, ?> optionsMap) {
319321
try {
320322
Tuple<String, Iterable<StorageObject>> result = runWithRetries(
@@ -333,7 +335,7 @@ public BlobInfo apply(StorageObject storageObject) {
333335
return BlobInfo.fromPb(storageObject);
334336
}
335337
});
336-
return new BaseListResult<>(new BlobPageFetcher(bucket, serviceOptions, cursor, optionsMap),
338+
return new BasePage<>(new BlobPageFetcher(bucket, serviceOptions, cursor, optionsMap),
337339
cursor,
338340
blobs);
339341
} catch (RetryHelperException e) {

gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobListResultTest.java renamed to gcloud-java-storage/src/test/java/com/google/gcloud/storage/BlobPageTest.java

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
import static org.junit.Assert.assertFalse;
2525

2626
import com.google.common.collect.ImmutableList;
27+
import com.google.gcloud.BasePage;
28+
import com.google.gcloud.Page;
2729

2830
import org.junit.Before;
2931
import org.junit.Test;
3032

3133
import java.util.Iterator;
3234

33-
public class BlobListResultTest {
35+
public class BlobPageTest {
3436

3537
private static final Iterable<BlobInfo> FIRST_PAGE_RESULTS = ImmutableList.of(
3638
BlobInfo.builder("b1", "n1").build(),
@@ -40,29 +42,29 @@ public class BlobListResultTest {
4042
BlobInfo.builder("b1", "n1").build(),
4143
BlobInfo.builder("b2", "n2").build());
4244

43-
private BaseListResult<BlobInfo> firstPage;
44-
private BaseListResult<BlobInfo> secondPage;
45+
private BasePage<BlobInfo> firstPage;
46+
private BasePage<BlobInfo> secondPage;
4547
private Storage storage;
46-
private BlobListResult blobListResult;
48+
private BlobPage blobPage;
4749

4850
@Before
4951
public void setUp() throws Exception {
50-
firstPage = createStrictMock(BaseListResult.class);
51-
secondPage = createStrictMock(BaseListResult.class);
52+
firstPage = createStrictMock(BasePage.class);
53+
secondPage = createStrictMock(BasePage.class);
5254
storage = createStrictMock(Storage.class);
53-
blobListResult = new BlobListResult(storage, firstPage);
55+
blobPage = new BlobPage(storage, firstPage);
5456
}
5557

5658
@Test
57-
public void testListResult() throws Exception {
59+
public void testPage() throws Exception {
5860
expect(firstPage.iterator()).andReturn(FIRST_PAGE_RESULTS.iterator());
5961
replay(firstPage);
6062
Iterator<BlobInfo> firstPageIterator = FIRST_PAGE_RESULTS.iterator();
61-
Iterator<Blob> blobListIterator = blobListResult.iterator();
62-
while (blobListIterator.hasNext() && firstPageIterator.hasNext()) {
63-
assertEquals(firstPageIterator.next(), blobListIterator.next().info());
63+
Iterator<Blob> pageIterator = blobPage.iterator();
64+
while (pageIterator.hasNext() && firstPageIterator.hasNext()) {
65+
assertEquals(firstPageIterator.next(), pageIterator.next().info());
6466
}
65-
assertFalse(blobListIterator.hasNext());
67+
assertFalse(pageIterator.hasNext());
6668
assertFalse(firstPageIterator.hasNext());
6769
verify(firstPage);
6870
}
@@ -71,7 +73,7 @@ public void testListResult() throws Exception {
7173
public void testCursor() throws Exception {
7274
expect(firstPage.nextPageCursor()).andReturn("c");
7375
replay(firstPage);
74-
assertEquals("c", blobListResult.nextPageCursor());
76+
assertEquals("c", blobPage.nextPageCursor());
7577
verify(firstPage);
7678
}
7779

@@ -81,7 +83,7 @@ public void testNextPage() throws Exception {
8183
expect(secondPage.iterator()).andReturn(SECOND_PAGE_RESULTS.iterator());
8284
replay(firstPage);
8385
replay(secondPage);
84-
ListResult<Blob> nextPageResult = blobListResult.nextPage();
86+
Page<Blob> nextPageResult = blobPage.nextPage();
8587
Iterator<BlobInfo> secondPageIterator = SECOND_PAGE_RESULTS.iterator();
8688
Iterator<Blob> blobListIterator = nextPageResult.iterator();
8789
while (blobListIterator.hasNext() && secondPageIterator.hasNext()) {

0 commit comments

Comments
 (0)