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