001 002package com.commercetools.api.models.common; 003 004import java.util.*; 005import java.util.function.Function; 006 007import javax.annotation.Nullable; 008 009import io.vrap.rmf.base.client.Builder; 010import io.vrap.rmf.base.client.utils.Generated; 011 012/** 013 * AssetBuilder 014 * <hr> 015 * Example to create an instance using the builder pattern 016 * <div class=code-example> 017 * <pre><code class='java'> 018 * Asset asset = Asset.builder() 019 * .id("{id}") 020 * .plusSources(sourcesBuilder -> sourcesBuilder) 021 * .name(nameBuilder -> nameBuilder) 022 * .build() 023 * </code></pre> 024 * </div> 025 */ 026@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 027public class AssetBuilder implements Builder<Asset> { 028 029 private String id; 030 031 private java.util.List<com.commercetools.api.models.common.AssetSource> sources; 032 033 private com.commercetools.api.models.common.LocalizedString name; 034 035 @Nullable 036 private com.commercetools.api.models.common.LocalizedString description; 037 038 @Nullable 039 private java.util.List<String> tags; 040 041 @Nullable 042 private com.commercetools.api.models.type.CustomFields custom; 043 044 @Nullable 045 private String key; 046 047 /** 048 * <p>Unique identifier of the Asset.</p> 049 * @param id value to be set 050 * @return Builder 051 */ 052 053 public AssetBuilder id(final String id) { 054 this.id = id; 055 return this; 056 } 057 058 /** 059 * set values to the sources 060 * @param sources value to be set 061 * @return Builder 062 */ 063 064 public AssetBuilder sources(final com.commercetools.api.models.common.AssetSource... sources) { 065 this.sources = new ArrayList<>(Arrays.asList(sources)); 066 return this; 067 } 068 069 /** 070 * set value to the sources 071 * @param sources value to be set 072 * @return Builder 073 */ 074 075 public AssetBuilder sources(final java.util.List<com.commercetools.api.models.common.AssetSource> sources) { 076 this.sources = sources; 077 return this; 078 } 079 080 /** 081 * add values to the sources 082 * @param sources value to be set 083 * @return Builder 084 */ 085 086 public AssetBuilder plusSources(final com.commercetools.api.models.common.AssetSource... sources) { 087 if (this.sources == null) { 088 this.sources = new ArrayList<>(); 089 } 090 this.sources.addAll(Arrays.asList(sources)); 091 return this; 092 } 093 094 /** 095 * add the value to the sources using the builder function 096 * @param builder function to build the sources value 097 * @return Builder 098 */ 099 100 public AssetBuilder plusSources( 101 Function<com.commercetools.api.models.common.AssetSourceBuilder, com.commercetools.api.models.common.AssetSourceBuilder> builder) { 102 if (this.sources == null) { 103 this.sources = new ArrayList<>(); 104 } 105 this.sources.add(builder.apply(com.commercetools.api.models.common.AssetSourceBuilder.of()).build()); 106 return this; 107 } 108 109 /** 110 * set the value to the sources using the builder function 111 * @param builder function to build the sources value 112 * @return Builder 113 */ 114 115 public AssetBuilder withSources( 116 Function<com.commercetools.api.models.common.AssetSourceBuilder, com.commercetools.api.models.common.AssetSourceBuilder> builder) { 117 this.sources = new ArrayList<>(); 118 this.sources.add(builder.apply(com.commercetools.api.models.common.AssetSourceBuilder.of()).build()); 119 return this; 120 } 121 122 /** 123 * add the value to the sources using the builder function 124 * @param builder function to build the sources value 125 * @return Builder 126 */ 127 128 public AssetBuilder addSources( 129 Function<com.commercetools.api.models.common.AssetSourceBuilder, com.commercetools.api.models.common.AssetSource> builder) { 130 return plusSources(builder.apply(com.commercetools.api.models.common.AssetSourceBuilder.of())); 131 } 132 133 /** 134 * set the value to the sources using the builder function 135 * @param builder function to build the sources value 136 * @return Builder 137 */ 138 139 public AssetBuilder setSources( 140 Function<com.commercetools.api.models.common.AssetSourceBuilder, com.commercetools.api.models.common.AssetSource> builder) { 141 return sources(builder.apply(com.commercetools.api.models.common.AssetSourceBuilder.of())); 142 } 143 144 /** 145 * <p>Name of the Asset.</p> 146 * @param builder function to build the name value 147 * @return Builder 148 */ 149 150 public AssetBuilder name( 151 Function<com.commercetools.api.models.common.LocalizedStringBuilder, com.commercetools.api.models.common.LocalizedStringBuilder> builder) { 152 this.name = builder.apply(com.commercetools.api.models.common.LocalizedStringBuilder.of()).build(); 153 return this; 154 } 155 156 /** 157 * <p>Name of the Asset.</p> 158 * @param builder function to build the name value 159 * @return Builder 160 */ 161 162 public AssetBuilder withName( 163 Function<com.commercetools.api.models.common.LocalizedStringBuilder, com.commercetools.api.models.common.LocalizedString> builder) { 164 this.name = builder.apply(com.commercetools.api.models.common.LocalizedStringBuilder.of()); 165 return this; 166 } 167 168 /** 169 * <p>Name of the Asset.</p> 170 * @param name value to be set 171 * @return Builder 172 */ 173 174 public AssetBuilder name(final com.commercetools.api.models.common.LocalizedString name) { 175 this.name = name; 176 return this; 177 } 178 179 /** 180 * <p>Description of the Asset.</p> 181 * @param builder function to build the description value 182 * @return Builder 183 */ 184 185 public AssetBuilder description( 186 Function<com.commercetools.api.models.common.LocalizedStringBuilder, com.commercetools.api.models.common.LocalizedStringBuilder> builder) { 187 this.description = builder.apply(com.commercetools.api.models.common.LocalizedStringBuilder.of()).build(); 188 return this; 189 } 190 191 /** 192 * <p>Description of the Asset.</p> 193 * @param builder function to build the description value 194 * @return Builder 195 */ 196 197 public AssetBuilder withDescription( 198 Function<com.commercetools.api.models.common.LocalizedStringBuilder, com.commercetools.api.models.common.LocalizedString> builder) { 199 this.description = builder.apply(com.commercetools.api.models.common.LocalizedStringBuilder.of()); 200 return this; 201 } 202 203 /** 204 * <p>Description of the Asset.</p> 205 * @param description value to be set 206 * @return Builder 207 */ 208 209 public AssetBuilder description(@Nullable final com.commercetools.api.models.common.LocalizedString description) { 210 this.description = description; 211 return this; 212 } 213 214 /** 215 * <p>Keywords for categorizing and organizing Assets.</p> 216 * @param tags value to be set 217 * @return Builder 218 */ 219 220 public AssetBuilder tags(@Nullable final String... tags) { 221 this.tags = new ArrayList<>(Arrays.asList(tags)); 222 return this; 223 } 224 225 /** 226 * <p>Keywords for categorizing and organizing Assets.</p> 227 * @param tags value to be set 228 * @return Builder 229 */ 230 231 public AssetBuilder tags(@Nullable final java.util.List<String> tags) { 232 this.tags = tags; 233 return this; 234 } 235 236 /** 237 * <p>Keywords for categorizing and organizing Assets.</p> 238 * @param tags value to be set 239 * @return Builder 240 */ 241 242 public AssetBuilder plusTags(@Nullable final String... tags) { 243 if (this.tags == null) { 244 this.tags = new ArrayList<>(); 245 } 246 this.tags.addAll(Arrays.asList(tags)); 247 return this; 248 } 249 250 /** 251 * <p>Custom Fields defined for the Asset.</p> 252 * @param builder function to build the custom value 253 * @return Builder 254 */ 255 256 public AssetBuilder custom( 257 Function<com.commercetools.api.models.type.CustomFieldsBuilder, com.commercetools.api.models.type.CustomFieldsBuilder> builder) { 258 this.custom = builder.apply(com.commercetools.api.models.type.CustomFieldsBuilder.of()).build(); 259 return this; 260 } 261 262 /** 263 * <p>Custom Fields defined for the Asset.</p> 264 * @param builder function to build the custom value 265 * @return Builder 266 */ 267 268 public AssetBuilder withCustom( 269 Function<com.commercetools.api.models.type.CustomFieldsBuilder, com.commercetools.api.models.type.CustomFields> builder) { 270 this.custom = builder.apply(com.commercetools.api.models.type.CustomFieldsBuilder.of()); 271 return this; 272 } 273 274 /** 275 * <p>Custom Fields defined for the Asset.</p> 276 * @param custom value to be set 277 * @return Builder 278 */ 279 280 public AssetBuilder custom(@Nullable final com.commercetools.api.models.type.CustomFields custom) { 281 this.custom = custom; 282 return this; 283 } 284 285 /** 286 * <p>User-defined unique identifier of the Asset.</p> 287 * @param key value to be set 288 * @return Builder 289 */ 290 291 public AssetBuilder key(@Nullable final String key) { 292 this.key = key; 293 return this; 294 } 295 296 /** 297 * <p>Unique identifier of the Asset.</p> 298 * @return id 299 */ 300 301 public String getId() { 302 return this.id; 303 } 304 305 /** 306 * value of sources} 307 * @return sources 308 */ 309 310 public java.util.List<com.commercetools.api.models.common.AssetSource> getSources() { 311 return this.sources; 312 } 313 314 /** 315 * <p>Name of the Asset.</p> 316 * @return name 317 */ 318 319 public com.commercetools.api.models.common.LocalizedString getName() { 320 return this.name; 321 } 322 323 /** 324 * <p>Description of the Asset.</p> 325 * @return description 326 */ 327 328 @Nullable 329 public com.commercetools.api.models.common.LocalizedString getDescription() { 330 return this.description; 331 } 332 333 /** 334 * <p>Keywords for categorizing and organizing Assets.</p> 335 * @return tags 336 */ 337 338 @Nullable 339 public java.util.List<String> getTags() { 340 return this.tags; 341 } 342 343 /** 344 * <p>Custom Fields defined for the Asset.</p> 345 * @return custom 346 */ 347 348 @Nullable 349 public com.commercetools.api.models.type.CustomFields getCustom() { 350 return this.custom; 351 } 352 353 /** 354 * <p>User-defined unique identifier of the Asset.</p> 355 * @return key 356 */ 357 358 @Nullable 359 public String getKey() { 360 return this.key; 361 } 362 363 /** 364 * builds Asset with checking for non-null required values 365 * @return Asset 366 */ 367 public Asset build() { 368 Objects.requireNonNull(id, Asset.class + ": id is missing"); 369 Objects.requireNonNull(sources, Asset.class + ": sources is missing"); 370 Objects.requireNonNull(name, Asset.class + ": name is missing"); 371 return new AssetImpl(id, sources, name, description, tags, custom, key); 372 } 373 374 /** 375 * builds Asset without checking for non-null required values 376 * @return Asset 377 */ 378 public Asset buildUnchecked() { 379 return new AssetImpl(id, sources, name, description, tags, custom, key); 380 } 381 382 /** 383 * factory method for an instance of AssetBuilder 384 * @return builder 385 */ 386 public static AssetBuilder of() { 387 return new AssetBuilder(); 388 } 389 390 /** 391 * create builder for Asset instance 392 * @param template instance with prefilled values for the builder 393 * @return builder 394 */ 395 public static AssetBuilder of(final Asset template) { 396 AssetBuilder builder = new AssetBuilder(); 397 builder.id = template.getId(); 398 builder.sources = template.getSources(); 399 builder.name = template.getName(); 400 builder.description = template.getDescription(); 401 builder.tags = template.getTags(); 402 builder.custom = template.getCustom(); 403 builder.key = template.getKey(); 404 return builder; 405 } 406 407}