Skip to content

Commit

Permalink
Merge pull request #416 from mziccard/fix-storage-to-builder
Browse files Browse the repository at this point in the history
Fix toBuilder so that info.equals(info.toBuilder().build()) is true
  • Loading branch information
aozarov committed Nov 25, 2015
2 parents bbc968e + 1a6dcde commit a25e504
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static final class Builder {
private String contentLanguage;
private Integer componentCount;
private String cacheControl;
private ImmutableList<Acl> acl;
private List<Acl> acl;
private Acl.Entity owner;
private Long size;
private String etag;
Expand All @@ -121,6 +121,29 @@ public static final class Builder {

private Builder() {}

private Builder(BlobInfo blobInfo) {
blobId = blobInfo.blobId;
id = blobInfo.id;
cacheControl = blobInfo.cacheControl;
contentEncoding = blobInfo.contentEncoding;
contentType = blobInfo.contentType;
contentDisposition = blobInfo.contentDisposition;
contentLanguage = blobInfo.contentLanguage;
componentCount = blobInfo.componentCount;
acl = blobInfo.acl;
owner = blobInfo.owner;
size = blobInfo.size;
etag = blobInfo.etag;
selfLink = blobInfo.selfLink;
md5 = blobInfo.md5;
crc32c = blobInfo.crc32c;
mediaLink = blobInfo.mediaLink;
metadata = blobInfo.metadata;
metageneration = blobInfo.metageneration;
deleteTime = blobInfo.deleteTime;
updateTime = blobInfo.updateTime;
}

/**
* Sets the blob identity.
*/
Expand Down Expand Up @@ -503,27 +526,7 @@ public Long updateTime() {
* Returns a builder for the current blob.
*/
public Builder toBuilder() {
return new Builder()
.blobId(blobId)
.id(id)
.cacheControl(cacheControl)
.contentEncoding(contentEncoding)
.contentType(contentType)
.contentDisposition(contentDisposition)
.contentLanguage(contentLanguage)
.componentCount(componentCount)
.crc32c(crc32c)
.md5(md5)
.deleteTime(deleteTime)
.updateTime(updateTime)
.mediaLink(mediaLink)
.metadata(metadata)
.metageneration(metageneration)
.acl(acl)
.owner(owner)
.size(size)
.etag(etag)
.selfLink(selfLink);
return new Builder(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,18 +325,37 @@ public static final class Builder {
private Boolean versioningEnabled;
private String indexPage;
private String notFoundPage;
private ImmutableList<DeleteRule> deleteRules;
private List<DeleteRule> deleteRules;
private String storageClass;
private String location;
private String etag;
private Long createTime;
private Long metageneration;
private ImmutableList<Cors> cors;
private ImmutableList<Acl> acl;
private ImmutableList<Acl> defaultAcl;
private List<Cors> cors;
private List<Acl> acl;
private List<Acl> defaultAcl;

private Builder() {}

private Builder(BucketInfo bucketInfo) {
id = bucketInfo.id;
name = bucketInfo.name;
etag = bucketInfo.etag;
createTime = bucketInfo.createTime;
metageneration = bucketInfo.metageneration;
location = bucketInfo.location;
storageClass = bucketInfo.storageClass;
cors = bucketInfo.cors;
acl = bucketInfo.acl;
defaultAcl = bucketInfo.defaultAcl;
owner = bucketInfo.owner;
selfLink = bucketInfo.selfLink;
versioningEnabled = bucketInfo.versioningEnabled;
indexPage = bucketInfo.indexPage;
notFoundPage = bucketInfo.notFoundPage;
deleteRules = bucketInfo.deleteRules;
}

/**
* Sets the bucket's name.
*/
Expand Down Expand Up @@ -629,23 +648,7 @@ public List<Acl> defaultAcl() {
* Returns a builder for the current bucket.
*/
public Builder toBuilder() {
return new Builder()
.name(name)
.id(id)
.createTime(createTime)
.etag(etag)
.metageneration(metageneration)
.cors(cors)
.acl(acl)
.defaultAcl(defaultAcl)
.location(location)
.storageClass(storageClass)
.owner(owner)
.selfLink(selfLink)
.versioningEnabled(versioningEnabled)
.indexPage(indexPage)
.notFoundPage(notFoundPage)
.deleteRules(deleteRules);
return new Builder(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public void testToBuilder() {
compareBlobs(BLOB_INFO, blobInfo);
}

@Test
public void testToBuilderIncomplete() {
BlobInfo incompleteBlobInfo = BlobInfo.builder(BlobId.of("b2", "n2")).build();
compareBlobs(incompleteBlobInfo, incompleteBlobInfo.toBuilder().build());
}

@Test
public void testBuilder() {
assertEquals("b", BLOB_INFO.bucket());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void testToBuilder() {
@Test
public void testToBuilderIncomplete() {
BucketInfo incompleteBucketInfo = BucketInfo.builder("b").build();
assertEquals(incompleteBucketInfo.name(), incompleteBucketInfo.toBuilder().build().name());
compareBuckets(incompleteBucketInfo, incompleteBucketInfo.toBuilder().build());
}

@Test
Expand Down

0 comments on commit a25e504

Please sign in to comment.