1919import static com .google .common .base .Preconditions .checkNotNull ;
2020
2121import com .google .api .core .BetaApi ;
22- import com .google .cloud .storage .Storage .BlobTargetOption ;
2322import com .google .cloud .storage .Storage .BlobWriteOption ;
2423import com .google .common .base .MoreObjects ;
2524import com .google .common .collect .ImmutableList ;
2625import java .util .List ;
2726import java .util .Objects ;
2827import org .checkerframework .checker .nullness .qual .NonNull ;
2928
29+ /**
30+ * Configuration for performing Parallel Uploads with {@link TransferManager}.
31+ *
32+ * @see Builder
33+ */
3034@ BetaApi
3135public final class ParallelUploadConfig {
3236
3337 private final boolean skipIfExists ;
3438 @ NonNull private final String prefix ;
3539 @ NonNull private final String bucketName ;
36- @ NonNull private final List <BlobTargetOption > targetOptsPerRequest ;
3740
3841 @ NonNull private final List <BlobWriteOption > writeOptsPerRequest ;
3942
4043 private ParallelUploadConfig (
4144 boolean skipIfExists ,
4245 @ NonNull String prefix ,
4346 @ NonNull String bucketName ,
44- @ NonNull List <BlobTargetOption > targetOptsPerRequest ,
4547 @ NonNull List <BlobWriteOption > writeOptsPerRequest ) {
4648 this .skipIfExists = skipIfExists ;
4749 this .prefix = prefix ;
4850 this .bucketName = bucketName ;
49- this .targetOptsPerRequest = targetOptsPerRequest ;
5051 this .writeOptsPerRequest = applySkipIfExists (skipIfExists , writeOptsPerRequest );
5152 }
5253
53- /** If a corresponding object already exists skip uploading the object */
54+ /**
55+ * If set Transfer Manager will skip uploading an object if it already exists, equivalent to
56+ * providing {@link BlobWriteOption#doesNotExist()} in {@link #getWriteOptsPerRequest()}
57+ *
58+ * @see Builder#setSkipIfExists(boolean)
59+ */
5460 @ BetaApi
5561 public boolean isSkipIfExists () {
5662 return skipIfExists ;
5763 }
5864
59- /** A common prefix that will be applied to all object paths in the destination bucket */
65+ /**
66+ * A common prefix that will be applied to all object paths in the destination bucket
67+ *
68+ * @see Builder#setPrefix(String)
69+ */
6070 @ BetaApi
6171 public @ NonNull String getPrefix () {
6272 return prefix ;
6373 }
6474
65- /** The bucket objects are being uploaded from */
75+ /**
76+ * The bucket objects are being uploaded from
77+ *
78+ * @see Builder#setBucketName(String)
79+ */
6680 @ BetaApi
6781 public @ NonNull String getBucketName () {
6882 return bucketName ;
6983 }
7084
71- /** A list of common BlobTargetOptions that are used for each upload request */
72- @ BetaApi
73- public @ NonNull List <BlobTargetOption > getTargetOptsPerRequest () {
74- return targetOptsPerRequest ;
75- }
76-
77- /** A list of common BlobWriteOptions that are used for each upload request */
85+ /**
86+ * A list of common BlobWriteOptions, note these options will be applied to each upload request.
87+ *
88+ * @see Builder#setWriteOptsPerRequest(List)
89+ */
7890 @ BetaApi
7991 public @ NonNull List <BlobWriteOption > getWriteOptsPerRequest () {
8092 return writeOptsPerRequest ;
@@ -92,12 +104,12 @@ public boolean equals(Object o) {
92104 return skipIfExists == that .skipIfExists
93105 && prefix .equals (that .prefix )
94106 && bucketName .equals (that .bucketName )
95- && targetOptsPerRequest .equals (that .targetOptsPerRequest );
107+ && writeOptsPerRequest .equals (that .writeOptsPerRequest );
96108 }
97109
98110 @ Override
99111 public int hashCode () {
100- return Objects .hash (skipIfExists , prefix , bucketName , targetOptsPerRequest );
112+ return Objects .hash (skipIfExists , prefix , bucketName , writeOptsPerRequest );
101113 }
102114
103115 @ Override
@@ -106,7 +118,7 @@ public String toString() {
106118 .add ("skipIfExists" , skipIfExists )
107119 .add ("prefix" , prefix )
108120 .add ("bucketName" , bucketName )
109- .add ("optionsPerRequest " , targetOptsPerRequest )
121+ .add ("writeOptsPerRequest " , writeOptsPerRequest )
110122 .toString ();
111123 }
112124
@@ -124,61 +136,86 @@ private static List<BlobWriteOption> applySkipIfExists(
124136 return writeOptsPerRequest ;
125137 }
126138
139+ /**
140+ * Builds an instance of ParallelUploadConfig.
141+ *
142+ * @see ParallelUploadConfig
143+ */
127144 @ BetaApi
128145 public static final class Builder {
129146
130147 private boolean skipIfExists ;
131148 private @ NonNull String prefix ;
132149 private @ NonNull String bucketName ;
133- private @ NonNull List <BlobTargetOption > optionsPerRequest ;
134-
135150 private @ NonNull List <BlobWriteOption > writeOptsPerRequest ;
136151
137152 private Builder () {
138153 this .prefix = "" ;
139154 this .bucketName = "" ;
140- this .optionsPerRequest = ImmutableList .of ();
141155 this .writeOptsPerRequest = ImmutableList .of ();
142156 }
143157
158+ /**
159+ * Sets the parameter for skipIfExists. When set to true Transfer Manager will skip uploading an
160+ * object if it already exists.
161+ *
162+ * @return the builder instance with the value for skipIfExists modified.
163+ * @see ParallelUploadConfig#isSkipIfExists()
164+ */
144165 @ BetaApi
145166 public Builder setSkipIfExists (boolean skipIfExists ) {
146167 this .skipIfExists = skipIfExists ;
147168 return this ;
148169 }
149170
171+ /**
172+ * Sets a common prefix that will be applied to all object paths in the destination bucket.
173+ *
174+ * @return the builder instance with the value for prefix modified.
175+ * @see ParallelUploadConfig#getPrefix()
176+ */
150177 @ BetaApi
151178 public Builder setPrefix (@ NonNull String prefix ) {
152179 this .prefix = prefix ;
153180 return this ;
154181 }
155182
183+ /**
184+ * Sets the bucketName that Transfer Manager will upload to. This field is required.
185+ *
186+ * @return the builder instance with the value for bucketName modified.
187+ * @see ParallelUploadConfig#getBucketName()
188+ */
156189 @ BetaApi
157190 public Builder setBucketName (@ NonNull String bucketName ) {
158191 this .bucketName = bucketName ;
159192 return this ;
160193 }
161194
162- @ BetaApi
163- public Builder setOptionsPerRequest (@ NonNull List <BlobTargetOption > optionsPerRequest ) {
164- this .optionsPerRequest = ImmutableList .copyOf (optionsPerRequest );
165- return this ;
166- }
167-
195+ /**
196+ * Sets the BlobWriteOptions that will be applied to each upload request. Note these options
197+ * will be applied to every single upload request.
198+ *
199+ * @return the builder instance with the value for WriteOptsPerRequest modified.
200+ * @see ParallelUploadConfig#getWriteOptsPerRequest()
201+ */
168202 @ BetaApi
169203 public Builder setWriteOptsPerRequest (@ NonNull List <BlobWriteOption > writeOptsPerRequest ) {
170204 this .writeOptsPerRequest = writeOptsPerRequest ;
171205 return this ;
172206 }
173207
208+ /**
209+ * Creates a ParallelUploadConfig object.
210+ *
211+ * @return {@link ParallelUploadConfig}
212+ */
174213 @ BetaApi
175214 public ParallelUploadConfig build () {
176215 checkNotNull (prefix );
177216 checkNotNull (bucketName );
178- checkNotNull (optionsPerRequest );
179217 checkNotNull (writeOptsPerRequest );
180- return new ParallelUploadConfig (
181- skipIfExists , prefix , bucketName , optionsPerRequest , writeOptsPerRequest );
218+ return new ParallelUploadConfig (skipIfExists , prefix , bucketName , writeOptsPerRequest );
182219 }
183220 }
184221}
0 commit comments