3434import com .google .common .base .Function ;
3535import com .google .common .base .MoreObjects ;
3636import com .google .common .collect .ImmutableList ;
37+ import com .google .common .collect .ImmutableMap ;
3738
3839import java .io .IOException ;
3940import java .io .ObjectInputStream ;
4041import java .io .ObjectOutputStream ;
4142import java .io .Serializable ;
4243import java .util .List ;
44+ import java .util .Map ;
4345import java .util .Objects ;
4446
4547/**
@@ -81,6 +83,7 @@ public com.google.api.services.storage.model.Bucket apply(BucketInfo bucketInfo)
8183 private final List <Acl > defaultAcl ;
8284 private final String location ;
8385 private final StorageClass storageClass ;
86+ private final Map <String , String > labels ;
8487
8588 /**
8689 * Base class for bucket's delete rules. Allows to configure automatic deletion of blobs and blobs
@@ -406,6 +409,11 @@ public abstract static class Builder {
406409 */
407410 public abstract Builder setDefaultAcl (Iterable <Acl > acl );
408411
412+ /**
413+ * Sets the label of this bucket.
414+ */
415+ public abstract Builder setLabels (Map <String , String > labels );
416+
409417 /**
410418 * Creates a {@code BucketInfo} object.
411419 */
@@ -430,6 +438,7 @@ static final class BuilderImpl extends Builder {
430438 private List <Cors > cors ;
431439 private List <Acl > acl ;
432440 private List <Acl > defaultAcl ;
441+ private Map <String , String > labels ;
433442
434443 BuilderImpl (String name ) {
435444 this .name = name ;
@@ -452,6 +461,7 @@ static final class BuilderImpl extends Builder {
452461 indexPage = bucketInfo .indexPage ;
453462 notFoundPage = bucketInfo .notFoundPage ;
454463 deleteRules = bucketInfo .deleteRules ;
464+ labels = bucketInfo .labels ;
455465 }
456466
457467 @ Override
@@ -550,6 +560,12 @@ public Builder setDefaultAcl(Iterable<Acl> acl) {
550560 return this ;
551561 }
552562
563+ @ Override
564+ public Builder setLabels (Map <String , String > labels ) {
565+ this .labels = labels != null ? ImmutableMap .copyOf (labels ) : null ;
566+ return this ;
567+ }
568+
553569 @ Override
554570 public BucketInfo build () {
555571 checkNotNull (name );
@@ -574,6 +590,7 @@ public BucketInfo build() {
574590 indexPage = builder .indexPage ;
575591 notFoundPage = builder .notFoundPage ;
576592 deleteRules = builder .deleteRules ;
593+ labels = builder .labels ;
577594 }
578595
579596 /**
@@ -708,6 +725,13 @@ public List<Acl> getDefaultAcl() {
708725 return defaultAcl ;
709726 }
710727
728+ /**
729+ * Returns the labels for this bucket.
730+ */
731+ public Map <String , String > getLabels () {
732+ return labels ;
733+ }
734+
711735 /**
712736 * Returns a builder for the current bucket.
713737 */
@@ -795,6 +819,10 @@ public Rule apply(DeleteRule deleteRule) {
795819 }));
796820 bucketPb .setLifecycle (lifecycle );
797821 }
822+ if (labels != null ) {
823+ bucketPb .setLabels (labels );
824+ }
825+
798826 return bucketPb ;
799827 }
800828
@@ -875,6 +903,9 @@ public DeleteRule apply(Rule rule) {
875903 }
876904 }));
877905 }
906+ if (bucketPb .getLabels () != null ) {
907+ builder .setLabels (bucketPb .getLabels ());
908+ }
878909 return builder .build ();
879910 }
880911}
0 commit comments