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 * ShippingRateDraftBuilder 014 * <hr> 015 * Example to create an instance using the builder pattern 016 * <div class=code-example> 017 * <pre><code class='java'> 018 * ShippingRateDraft shippingRateDraft = ShippingRateDraft.builder() 019 * .price(priceBuilder -> priceBuilder) 020 * .build() 021 * </code></pre> 022 * </div> 023 */ 024@Generated(value = "io.vrap.rmf.codegen.rendering.CoreCodeGenerator", comments = "https://github.com/commercetools/rmf-codegen") 025public class ShippingRateDraftBuilder implements Builder<ShippingRateDraft> { 026 027 private com.commercetools.importapi.models.common.Money price; 028 029 @Nullable 030 private com.commercetools.importapi.models.common.Money freeAbove; 031 032 @Nullable 033 private java.util.List<com.commercetools.importapi.models.orders.ShippingRatePriceTier> tiers; 034 035 /** 036 * set the value to the price using the builder function 037 * @param builder function to build the price value 038 * @return Builder 039 */ 040 041 public ShippingRateDraftBuilder price( 042 Function<com.commercetools.importapi.models.common.MoneyBuilder, com.commercetools.importapi.models.common.MoneyBuilder> builder) { 043 this.price = builder.apply(com.commercetools.importapi.models.common.MoneyBuilder.of()).build(); 044 return this; 045 } 046 047 /** 048 * set the value to the price using the builder function 049 * @param builder function to build the price value 050 * @return Builder 051 */ 052 053 public ShippingRateDraftBuilder withPrice( 054 Function<com.commercetools.importapi.models.common.MoneyBuilder, com.commercetools.importapi.models.common.Money> builder) { 055 this.price = builder.apply(com.commercetools.importapi.models.common.MoneyBuilder.of()); 056 return this; 057 } 058 059 /** 060 * set the value to the price 061 * @param price value to be set 062 * @return Builder 063 */ 064 065 public ShippingRateDraftBuilder price(final com.commercetools.importapi.models.common.Money price) { 066 this.price = price; 067 return this; 068 } 069 070 /** 071 * set the value to the freeAbove using the builder function 072 * @param builder function to build the freeAbove value 073 * @return Builder 074 */ 075 076 public ShippingRateDraftBuilder freeAbove( 077 Function<com.commercetools.importapi.models.common.MoneyBuilder, com.commercetools.importapi.models.common.MoneyBuilder> builder) { 078 this.freeAbove = builder.apply(com.commercetools.importapi.models.common.MoneyBuilder.of()).build(); 079 return this; 080 } 081 082 /** 083 * set the value to the freeAbove using the builder function 084 * @param builder function to build the freeAbove value 085 * @return Builder 086 */ 087 088 public ShippingRateDraftBuilder withFreeAbove( 089 Function<com.commercetools.importapi.models.common.MoneyBuilder, com.commercetools.importapi.models.common.Money> builder) { 090 this.freeAbove = builder.apply(com.commercetools.importapi.models.common.MoneyBuilder.of()); 091 return this; 092 } 093 094 /** 095 * set the value to the freeAbove 096 * @param freeAbove value to be set 097 * @return Builder 098 */ 099 100 public ShippingRateDraftBuilder freeAbove( 101 @Nullable final com.commercetools.importapi.models.common.Money freeAbove) { 102 this.freeAbove = freeAbove; 103 return this; 104 } 105 106 /** 107 * set values to the tiers 108 * @param tiers value to be set 109 * @return Builder 110 */ 111 112 public ShippingRateDraftBuilder tiers( 113 @Nullable final com.commercetools.importapi.models.orders.ShippingRatePriceTier... tiers) { 114 this.tiers = new ArrayList<>(Arrays.asList(tiers)); 115 return this; 116 } 117 118 /** 119 * set value to the tiers 120 * @param tiers value to be set 121 * @return Builder 122 */ 123 124 public ShippingRateDraftBuilder tiers( 125 @Nullable final java.util.List<com.commercetools.importapi.models.orders.ShippingRatePriceTier> tiers) { 126 this.tiers = tiers; 127 return this; 128 } 129 130 /** 131 * add values to the tiers 132 * @param tiers value to be set 133 * @return Builder 134 */ 135 136 public ShippingRateDraftBuilder plusTiers( 137 @Nullable final com.commercetools.importapi.models.orders.ShippingRatePriceTier... tiers) { 138 if (this.tiers == null) { 139 this.tiers = new ArrayList<>(); 140 } 141 this.tiers.addAll(Arrays.asList(tiers)); 142 return this; 143 } 144 145 /** 146 * add a value to the tiers using the builder function 147 * @param builder function to build the tiers value 148 * @return Builder 149 */ 150 151 public ShippingRateDraftBuilder plusTiers( 152 Function<com.commercetools.importapi.models.orders.ShippingRatePriceTierBuilder, Builder<? extends com.commercetools.importapi.models.orders.ShippingRatePriceTier>> builder) { 153 if (this.tiers == null) { 154 this.tiers = new ArrayList<>(); 155 } 156 this.tiers.add( 157 builder.apply(com.commercetools.importapi.models.orders.ShippingRatePriceTierBuilder.of()).build()); 158 return this; 159 } 160 161 /** 162 * set the value to the tiers using the builder function 163 * @param builder function to build the tiers value 164 * @return Builder 165 */ 166 167 public ShippingRateDraftBuilder withTiers( 168 Function<com.commercetools.importapi.models.orders.ShippingRatePriceTierBuilder, Builder<? extends com.commercetools.importapi.models.orders.ShippingRatePriceTier>> builder) { 169 this.tiers = new ArrayList<>(); 170 this.tiers.add( 171 builder.apply(com.commercetools.importapi.models.orders.ShippingRatePriceTierBuilder.of()).build()); 172 return this; 173 } 174 175 /** 176 * value of price} 177 * @return price 178 */ 179 180 public com.commercetools.importapi.models.common.Money getPrice() { 181 return this.price; 182 } 183 184 /** 185 * value of freeAbove} 186 * @return freeAbove 187 */ 188 189 @Nullable 190 public com.commercetools.importapi.models.common.Money getFreeAbove() { 191 return this.freeAbove; 192 } 193 194 /** 195 * value of tiers} 196 * @return tiers 197 */ 198 199 @Nullable 200 public java.util.List<com.commercetools.importapi.models.orders.ShippingRatePriceTier> getTiers() { 201 return this.tiers; 202 } 203 204 /** 205 * builds ShippingRateDraft with checking for non-null required values 206 * @return ShippingRateDraft 207 */ 208 public ShippingRateDraft build() { 209 Objects.requireNonNull(price, ShippingRateDraft.class + ": price is missing"); 210 return new ShippingRateDraftImpl(price, freeAbove, tiers); 211 } 212 213 /** 214 * builds ShippingRateDraft without checking for non-null required values 215 * @return ShippingRateDraft 216 */ 217 public ShippingRateDraft buildUnchecked() { 218 return new ShippingRateDraftImpl(price, freeAbove, tiers); 219 } 220 221 /** 222 * factory method for an instance of ShippingRateDraftBuilder 223 * @return builder 224 */ 225 public static ShippingRateDraftBuilder of() { 226 return new ShippingRateDraftBuilder(); 227 } 228 229 /** 230 * create builder for ShippingRateDraft instance 231 * @param template instance with prefilled values for the builder 232 * @return builder 233 */ 234 public static ShippingRateDraftBuilder of(final ShippingRateDraft template) { 235 ShippingRateDraftBuilder builder = new ShippingRateDraftBuilder(); 236 builder.price = template.getPrice(); 237 builder.freeAbove = template.getFreeAbove(); 238 builder.tiers = template.getTiers(); 239 return builder; 240 } 241 242}