001 002package com.commercetools.importapi.models.orders; 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 * DeliveryBuilder 014 * <hr> 015 * Example to create an instance using the builder pattern 016 * <div class=code-example> 017 * <pre><code class='java'> 018 * Delivery delivery = Delivery.builder() 019 * .id("{id}") 020 * .createdAt(ZonedDateTime.parse("2022-01-01T12:00:00.301Z")) 021 * .plusItems(itemsBuilder -> itemsBuilder) 022 * .plusParcels(parcelsBuilder -> parcelsBuilder) 023 * .build() 024 * </code></pre> 025 * </div> 026 */ 027@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 028public class DeliveryBuilder implements Builder<Delivery> { 029 030 private String id; 031 032 private java.time.ZonedDateTime createdAt; 033 034 private java.util.List<com.commercetools.importapi.models.orders.DeliveryItem> items; 035 036 private java.util.List<com.commercetools.importapi.models.orders.Parcel> parcels; 037 038 @Nullable 039 private com.commercetools.importapi.models.common.Address address; 040 041 /** 042 * set the value to the id 043 * @param id value to be set 044 * @return Builder 045 */ 046 047 public DeliveryBuilder id(final String id) { 048 this.id = id; 049 return this; 050 } 051 052 /** 053 * set the value to the createdAt 054 * @param createdAt value to be set 055 * @return Builder 056 */ 057 058 public DeliveryBuilder createdAt(final java.time.ZonedDateTime createdAt) { 059 this.createdAt = createdAt; 060 return this; 061 } 062 063 /** 064 * set values to the items 065 * @param items value to be set 066 * @return Builder 067 */ 068 069 public DeliveryBuilder items(final com.commercetools.importapi.models.orders.DeliveryItem... items) { 070 this.items = new ArrayList<>(Arrays.asList(items)); 071 return this; 072 } 073 074 /** 075 * set value to the items 076 * @param items value to be set 077 * @return Builder 078 */ 079 080 public DeliveryBuilder items(final java.util.List<com.commercetools.importapi.models.orders.DeliveryItem> items) { 081 this.items = items; 082 return this; 083 } 084 085 /** 086 * add values to the items 087 * @param items value to be set 088 * @return Builder 089 */ 090 091 public DeliveryBuilder plusItems(final com.commercetools.importapi.models.orders.DeliveryItem... items) { 092 if (this.items == null) { 093 this.items = new ArrayList<>(); 094 } 095 this.items.addAll(Arrays.asList(items)); 096 return this; 097 } 098 099 /** 100 * add the value to the items using the builder function 101 * @param builder function to build the items value 102 * @return Builder 103 */ 104 105 public DeliveryBuilder plusItems( 106 Function<com.commercetools.importapi.models.orders.DeliveryItemBuilder, com.commercetools.importapi.models.orders.DeliveryItemBuilder> builder) { 107 if (this.items == null) { 108 this.items = new ArrayList<>(); 109 } 110 this.items.add(builder.apply(com.commercetools.importapi.models.orders.DeliveryItemBuilder.of()).build()); 111 return this; 112 } 113 114 /** 115 * set the value to the items using the builder function 116 * @param builder function to build the items value 117 * @return Builder 118 */ 119 120 public DeliveryBuilder withItems( 121 Function<com.commercetools.importapi.models.orders.DeliveryItemBuilder, com.commercetools.importapi.models.orders.DeliveryItemBuilder> builder) { 122 this.items = new ArrayList<>(); 123 this.items.add(builder.apply(com.commercetools.importapi.models.orders.DeliveryItemBuilder.of()).build()); 124 return this; 125 } 126 127 /** 128 * add the value to the items using the builder function 129 * @param builder function to build the items value 130 * @return Builder 131 */ 132 133 public DeliveryBuilder addItems( 134 Function<com.commercetools.importapi.models.orders.DeliveryItemBuilder, com.commercetools.importapi.models.orders.DeliveryItem> builder) { 135 return plusItems(builder.apply(com.commercetools.importapi.models.orders.DeliveryItemBuilder.of())); 136 } 137 138 /** 139 * set the value to the items using the builder function 140 * @param builder function to build the items value 141 * @return Builder 142 */ 143 144 public DeliveryBuilder setItems( 145 Function<com.commercetools.importapi.models.orders.DeliveryItemBuilder, com.commercetools.importapi.models.orders.DeliveryItem> builder) { 146 return items(builder.apply(com.commercetools.importapi.models.orders.DeliveryItemBuilder.of())); 147 } 148 149 /** 150 * set values to the parcels 151 * @param parcels value to be set 152 * @return Builder 153 */ 154 155 public DeliveryBuilder parcels(final com.commercetools.importapi.models.orders.Parcel... parcels) { 156 this.parcels = new ArrayList<>(Arrays.asList(parcels)); 157 return this; 158 } 159 160 /** 161 * set value to the parcels 162 * @param parcels value to be set 163 * @return Builder 164 */ 165 166 public DeliveryBuilder parcels(final java.util.List<com.commercetools.importapi.models.orders.Parcel> parcels) { 167 this.parcels = parcels; 168 return this; 169 } 170 171 /** 172 * add values to the parcels 173 * @param parcels value to be set 174 * @return Builder 175 */ 176 177 public DeliveryBuilder plusParcels(final com.commercetools.importapi.models.orders.Parcel... parcels) { 178 if (this.parcels == null) { 179 this.parcels = new ArrayList<>(); 180 } 181 this.parcels.addAll(Arrays.asList(parcels)); 182 return this; 183 } 184 185 /** 186 * add the value to the parcels using the builder function 187 * @param builder function to build the parcels value 188 * @return Builder 189 */ 190 191 public DeliveryBuilder plusParcels( 192 Function<com.commercetools.importapi.models.orders.ParcelBuilder, com.commercetools.importapi.models.orders.ParcelBuilder> builder) { 193 if (this.parcels == null) { 194 this.parcels = new ArrayList<>(); 195 } 196 this.parcels.add(builder.apply(com.commercetools.importapi.models.orders.ParcelBuilder.of()).build()); 197 return this; 198 } 199 200 /** 201 * set the value to the parcels using the builder function 202 * @param builder function to build the parcels value 203 * @return Builder 204 */ 205 206 public DeliveryBuilder withParcels( 207 Function<com.commercetools.importapi.models.orders.ParcelBuilder, com.commercetools.importapi.models.orders.ParcelBuilder> builder) { 208 this.parcels = new ArrayList<>(); 209 this.parcels.add(builder.apply(com.commercetools.importapi.models.orders.ParcelBuilder.of()).build()); 210 return this; 211 } 212 213 /** 214 * add the value to the parcels using the builder function 215 * @param builder function to build the parcels value 216 * @return Builder 217 */ 218 219 public DeliveryBuilder addParcels( 220 Function<com.commercetools.importapi.models.orders.ParcelBuilder, com.commercetools.importapi.models.orders.Parcel> builder) { 221 return plusParcels(builder.apply(com.commercetools.importapi.models.orders.ParcelBuilder.of())); 222 } 223 224 /** 225 * set the value to the parcels using the builder function 226 * @param builder function to build the parcels value 227 * @return Builder 228 */ 229 230 public DeliveryBuilder setParcels( 231 Function<com.commercetools.importapi.models.orders.ParcelBuilder, com.commercetools.importapi.models.orders.Parcel> builder) { 232 return parcels(builder.apply(com.commercetools.importapi.models.orders.ParcelBuilder.of())); 233 } 234 235 /** 236 * set the value to the address using the builder function 237 * @param builder function to build the address value 238 * @return Builder 239 */ 240 241 public DeliveryBuilder address( 242 Function<com.commercetools.importapi.models.common.AddressBuilder, com.commercetools.importapi.models.common.AddressBuilder> builder) { 243 this.address = builder.apply(com.commercetools.importapi.models.common.AddressBuilder.of()).build(); 244 return this; 245 } 246 247 /** 248 * set the value to the address using the builder function 249 * @param builder function to build the address value 250 * @return Builder 251 */ 252 253 public DeliveryBuilder withAddress( 254 Function<com.commercetools.importapi.models.common.AddressBuilder, com.commercetools.importapi.models.common.Address> builder) { 255 this.address = builder.apply(com.commercetools.importapi.models.common.AddressBuilder.of()); 256 return this; 257 } 258 259 /** 260 * set the value to the address 261 * @param address value to be set 262 * @return Builder 263 */ 264 265 public DeliveryBuilder address(@Nullable final com.commercetools.importapi.models.common.Address address) { 266 this.address = address; 267 return this; 268 } 269 270 /** 271 * value of id} 272 * @return id 273 */ 274 275 public String getId() { 276 return this.id; 277 } 278 279 /** 280 * value of createdAt} 281 * @return createdAt 282 */ 283 284 public java.time.ZonedDateTime getCreatedAt() { 285 return this.createdAt; 286 } 287 288 /** 289 * value of items} 290 * @return items 291 */ 292 293 public java.util.List<com.commercetools.importapi.models.orders.DeliveryItem> getItems() { 294 return this.items; 295 } 296 297 /** 298 * value of parcels} 299 * @return parcels 300 */ 301 302 public java.util.List<com.commercetools.importapi.models.orders.Parcel> getParcels() { 303 return this.parcels; 304 } 305 306 /** 307 * value of address} 308 * @return address 309 */ 310 311 @Nullable 312 public com.commercetools.importapi.models.common.Address getAddress() { 313 return this.address; 314 } 315 316 /** 317 * builds Delivery with checking for non-null required values 318 * @return Delivery 319 */ 320 public Delivery build() { 321 Objects.requireNonNull(id, Delivery.class + ": id is missing"); 322 Objects.requireNonNull(createdAt, Delivery.class + ": createdAt is missing"); 323 Objects.requireNonNull(items, Delivery.class + ": items is missing"); 324 Objects.requireNonNull(parcels, Delivery.class + ": parcels is missing"); 325 return new DeliveryImpl(id, createdAt, items, parcels, address); 326 } 327 328 /** 329 * builds Delivery without checking for non-null required values 330 * @return Delivery 331 */ 332 public Delivery buildUnchecked() { 333 return new DeliveryImpl(id, createdAt, items, parcels, address); 334 } 335 336 /** 337 * factory method for an instance of DeliveryBuilder 338 * @return builder 339 */ 340 public static DeliveryBuilder of() { 341 return new DeliveryBuilder(); 342 } 343 344 /** 345 * create builder for Delivery instance 346 * @param template instance with prefilled values for the builder 347 * @return builder 348 */ 349 public static DeliveryBuilder of(final Delivery template) { 350 DeliveryBuilder builder = new DeliveryBuilder(); 351 builder.id = template.getId(); 352 builder.createdAt = template.getCreatedAt(); 353 builder.items = template.getItems(); 354 builder.parcels = template.getParcels(); 355 builder.address = template.getAddress(); 356 return builder; 357 } 358 359}